I´m building an Android Application and trying the default navigation that Android Studio generates from the scratch.
How should i open a new fragment inside another fragment?
I´m building an Android Application and trying the default navigation that Android Studio generates from the scratch.
How should i open a new fragment inside another fragment?
Replace Fragment B from Fragment A:
FragmentManager fragmentManager = getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout_container, new fragmentB());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Done
You can use this approach. You define an Interface, Implement the Interface on an activity, store an instance of the interface that you defined (using onAttach call) and cal the methods there whenever you need them.
Fragments should be independent, and they don't know about any other fragment on your application