I am getting an error “The method show(FragmentManager, String)”

后端 未结 6 1078
礼貌的吻别
礼貌的吻别 2020-12-09 02:17

I am getting an error

The method show(FragmentManager, String) in the type DialogFragment is not applicable for the argumen

相关标签:
6条回答
  • 2020-12-09 02:46

    The problem is because you need to be using the support package's FragmentManager but you are using the native FragmentManager when you call getFragmentManager(). Try calling getSupportFragmentManager() when initializing your variable fm

    you also have to make sure that you include DialogFragment from the Support package and not from the native package.

    You can do that by importing,

    import android.support.v4.app.DialogFragment;
    
    0 讨论(0)
  • 2020-12-09 02:47

    You should use android.support.v4.app.FragmentManager instead of android.app.FragmentManager.

    Then you should call getSupportFragmentManager() but not getFragmentManager()

    0 讨论(0)
  • 2020-12-09 02:50
    public void onClick(View v) {
    
        switch (v.getId()) {
        case R.id.btnselectDate:
             DialogFragment newFragment = new DatePickerFragment();
             newFragment.show(this.getFragmentManager(), "datePicker");
             break;
    
             default:
             break;
         }
    }
    
    0 讨论(0)
  • 2020-12-09 02:56

    I got this when opening a DialogFragment even though I was not using android.support.v4.app.DialogFragment. I had to call getActivity().getFragmentManager(), because getSupportFragmentManager() didn't work.

    0 讨论(0)
  • 2020-12-09 02:57

    Even i had the same problem when running the code in gingerbread. But works fine for ICS. The solution is,

    instead of this:

    public class MainActivity extends Activity {
    }
    

    use extends FragmentActivty

    public class MainActivity extends FragmentActivity {
    }
    
    0 讨论(0)
  • 2020-12-09 03:07

    As you're using android.support.v4.app.DialogFragment, you should pass to show() an instance of android.support.v4.app.FragmentManager which can be queried using an getSupportFragmentManager() call. Hope this helps.

    0 讨论(0)
提交回复
热议问题