1

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.

Blo
  • 11,903
  • 5
  • 45
  • 99
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

2 Answers2

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.

Paul Burke
  • 25,496
  • 9
  • 66
  • 62
  • it's not quite what I needed. I'm not using a FrameLayout, but instead the fragments are managed by a FragmentPagerAdapter – Christopher Francisco Oct 02 '13 at 13:15
  • That makes no difference. Put a `FrameLayout` as a view in your `Fragment` layouts. – Paul Burke Oct 02 '13 at 13:16
  • You mean that the 4th Tab contains a fragment with a FrameLayout, and inside that FrameLayout, I put my 2 fragments that I want to switch between to? – Christopher Francisco Oct 02 '13 at 13:20
  • 1
    No, in the layout that you use in `onCreateView`, put a `FrameLayout` at the "top" that can be used for the `FragmentTransaction`. If you show me the layout you're using for the `Fragments`, themselves, I can show you exactly what I mean. – Paul Burke Oct 02 '13 at 13:38
-1

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

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206