FDuhen
FDuhen

Reputation: 4836

Android Change main Fragment from child

I'm having some troubles with my Fragments management..
It's quite new for me and I'm pretty sure you'll find an easy way to solve my problem.

So I have a NavigationDrawer in a FragmentActivity and from this, I can navigate between two fragments.
One of those two fragments has children in a ViewPager.
I'd like to change the Parent Fragment from a ChildFragment which is in the ViewPager..

With my friend Paint, I drew my problem
http://goo.gl/OGdf1c
So as you can see, I'd like to load FragmentA from Fragment2B

Thank you !

Upvotes: 1

Views: 604

Answers (1)

Xaver Kapeller
Xaver Kapeller

Reputation: 49837

Just perform a normal FragmentTransaction and be sure to use the FragmentManager of the Activity!

FragmentManager manager = getActivity().getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(...);
transaction.commit();

If your Activity is a FragmentActivity or ActionBarActivity you have to remember to use the support FragmentManager, aside from that everything stays the same:

FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(...);
transaction.commit();

Upvotes: 1

Related Questions