Cannot resolve for method show(android.app.Fragmen

2019-02-25 20:48发布

问题:

I've on API 23.Using RadialTimePickerDialogFragment that uses v4 The parent activity is based on Activity (we don't need

Why am I getting

Cannot resolve for method show(android.app.FragmentManager, java.lang.String)

import com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment;
import android.support.v4.app.DialogFragment;

import com.gtfp.workingmemory.BuildConfig;
import com.gtfp.workingmemory.R;
import com.gtfp.workingmemory.colorPicker.colorPickerActivity;
import com.gtfp.workingmemory.colorPicker.colorPickerView;
import com.gtfp.workingmemory.frmwrk.frmwrkActivity;
import com.gtfp.workingmemory.settings.SettingsActivity;
import com.gtfp.workingmemory.settings.appSettings;
import com.gtfp.workingmemory.todo.ToDoAlarm;
import com.gtfp.workingmemory.todo.ToDoItem;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
    :
    :
    :
    :
     RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment()
                            .setOnTimeSetListener(editToDoItem.this)
                            .setStartTime(10, 10)
                            .setThemeDark();

                    rtpd.show(getFragmentManager(), FRAG_TAG_TIME_PICKER);

回答1:

Solution:
The show method in RadialTimePickerDialogFragment required the v4 FragmentManager (ie. getSupportFragmentManager). Obviously, RadialTimePickerDialogFragment is an old class.

This means changing the parent Activity from extending Activity to extending android.support.v4.app.FragmentActivity and using getSupportFragmentManager() instead of getFragmentManager().

public class editToDoItem extends android.support.v4.app.FragmentActivity
:
:
:
RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment()
                .setOnTimeSetListener(editToDoItem.this)
                .setStartTime(mTP.getCurrentHour(),mTP.getCurrentMinute());

rtpd.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER);