001. Replacing fragment inside a fragment

What: I was trying to replace a FrameLayout inside a fragment with a listView. Since the listView itself is also a fragment, we are essentially trying to replace a fragment inside a fragment.

Normally, we would simply do

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

to complete a fragment replacement inside an activity.

How: to replace a fragment inside a fragment, we would only need to replace getSupportFragmentManager() with getChildFragmentManager().

Fragment fragment = new RecyclerListFragment();
.replace(R.id.content_fragment, fragment)

Detail: from Android developer documentations

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.