سؤال

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.

هل كانت مفيدة؟

المحلول 2

I'll just drop this idea and change to use Activity.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top