Search code examples
androidandroid-fragmentsfragmentpageradapterfragmenttransactionandroid-nested-fragment

Commiting FragmentTransaction in 1 Tab of a FragmentPagerAdapter


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.


Solution

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