0
votes

I create an activity container where I added an fragment using :

FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.simple_fragment, myFragment); ft.commit();

where simple_fragment is container layout (Linear/Frame), now I want to add another fragment in myFragment from myFragment itself.

UPDATE :

Pleas refer attached image, in this case I have activity layout with three top button, in click of every button i replace downside layout with other fragment layout say Fragment 1/2 or 3 ....now from fragment 1 i want to call other fragment 1A and from 1A to 1B. Here I want to maintain stack as well for inner fragment view.

enter image description here

How can I do this, any one have idea/suggestion about it?

2
Fragments inside another fragment is possible since 4.2Ion Aalbers
developer.android.com/about/versions/… Its says its inside the latest Support Lib (Sorry no examples)Ion Aalbers
ok np let me check this..thanks.CoDe

2 Answers

0
votes

Access the Activity that is hosting the Fragment and ask it to replace your Fragment.

Something like

((MyActivity) getActivity()).goToOtherFragment();
0
votes

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();