I'm not sure what type of layout you're using for your DialogFragment, but generally in the XML that DialogFragment inflates you need to add a FrameLayout
and importantly give it an ID. Then when you do your fragment transaction you pass in the resource id of that FrameLayout
XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
If you want to use nested fragments you'll need to call getChildFragmentManager()
:
FragmentManager fragmentManager = getChildFragmentManager()
Then for your fragment transaction:
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, new MyFragment()).commit();
You might want to use the add
method instead of replace
, but thats up to you
You might also want to add the previous fragment to the backstack if you want the enable back button presses:
fragmentTransaction.replace(R.id.fragment_container, new MyFragment()).addToBackStack(null).commit();