Add Fragment Into Fragment?
I create an activity container where I added an fragment using : FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.simple_fragment, myFragment);
Solution 1:
Access the Activity that is hosting the Fragment and ask it to replace your Fragment.
Something like
((MyActivity) getActivity()).goToOtherFragment();
Solution 2:
in your 1A fragment you have to give an id to the parent view that will hold the 1B fragment example
<FrameLayout android:id="@+id/content"/>
then you have to add the new 1B fragment to 1A
Fragment1B fragment1B = new Fragment1B();
FragmentTransaction transaction=getFragmentManager().beginTransaction();
transaction.add(R.id.content,fragment1B,"fragment1BTAG");
transaction.addToBackStack(null);
transaction.commit();
and some times you need to set the background color of your 1B fragment root view to white , because it load as trasnparent
then in your onBackPressed() you can just use the
FragmentManager fm=getSupportFragmentManager();
fm.popBackStack();
Post a Comment for "Add Fragment Into Fragment?"