问题
I'm using FragmentPageAdapter
to have multiple tabs within my app. 1 of those tabs is a ListFragment
that is supposed to be replaced by another fragment onItemClick
, using FragmentTransaction
.
The change replace works perfectly if I add the ListFragment
to a FrameLayout
inside an Activity
, but I'm not sure how to do this using FragmentPagerAdapter
.
Here's a better explanation:
Tab1 Tab2 Tab3 Tab4
fragment fragment fragment fragment
subclass subclass subclass listview
after clicking on one item from the fragment listview it should be replaced like this
Tab1 Tab2 Tab3 Tab4
fragment fragment fragment fragment
subclass subclass subclass another-one
I tried using .replace(((ViewGroup)getView().getParent()).getId(), newFragment).commit()
, but it doesn't work.
回答1:
If you know it's always going to replace the Fragment
on that page, then why not use a child Fragment
?
Instead of using getFragmentManager()
you use getChildFragmentManager()
and put the FrameLayout
at the top of the layout that you're using for the Fragment
.
回答2:
I'll just drop this idea and change to use Activity
.
来源:https://stackoverflow.com/questions/18968972/commiting-fragmenttransaction-in-1-tab-of-a-fragmentpageradapter