Show DialogFragment from another DialogFragment

前端 未结 9 899
春和景丽
春和景丽 2021-02-05 10:33

I have a DialogFragment that displays a list of options to the user, one of these options is \"Delete\" option, when the user presses the delete option I want to sh

9条回答
  •  感动是毒
    2021-02-05 10:53

    Very recently, I had this problem and none of the options above worked for me. I tried using the method below:

    DialogFragment fragment = new MyFragment(); //where MyFragment is my fragment I want to show
    fragment.setCancelable(true);
    fragment.show(getSupportFragmentManager(), "timePicker");
    

    This will ONLY work if you're using this in an activity (i.e to call a dialog fragment from an activity class).

    I however fixed this by downcasting my activity instance to an AppCompat activity and using it to call getSupportFragment() as shown below:

    DialogFragment timeFragment = new TimePicker();
    timeFragment.setCancelable(true);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    timeFragment.show(activity.getSupportFragmentManager(), "timePicker");
    

    I hope this helps.. Merry coding!!

提交回复
热议问题