0

I asked this question before getChildFragmentManager() and viewpager without any responses, probably because the explanation was too long.

Simply put I have a viewpager inside a fragment. The pages inside that viewpager need to be replaced through a series of screens. Pressing back on those screens will not exit the application. How do I do this?

challenges:

  1. viewpager xml does not use framelayout. when I use the replace method, what container id do I use?

  2. when replacing the fragments why would I use getChildFragmentManager each time if that is private to the current fragment?

@goonedroid: that's not the case I'm looking for here. The only similarity is that the fragment has a viewpager. My viewpager's pages need to be replaced when clicked:

I have a navdrawer. Clicking item 2 shows FragmentA. Clicking FragmentA replaces it with FragmentB. Clicking FragmentB replaces it with FragmentC. Clicking FragmentC takes you back to FragmentB. Fragments are added to the backstack for proper back navigation.

Clicking item 1 in the navdrawer shows FragmentZ with a viewpager. The viewpagers pages are just FragmentA and all the aforementioned behavior. But going from A to B here, then pressing back shows no pages in the viewpager.

Community
  • 1
  • 1
HukeLau_DABA
  • 2,384
  • 6
  • 33
  • 51
  • To replace fragments inside Viewpager, you should use viewpager's setCurrentItem() method. – jimmy0251 Oct 04 '14 at 06:26
  • setCurrentItem only sets the current page of the viewpager. I click on a page in the viewpager and want a new fragment to replace it. When I click back, it should take me to the original page in the viewpager. – HukeLau_DABA Oct 04 '14 at 06:49
  • use this answer http://stackoverflow.com/questions/18588944/replace-one-fragment-with-another-in-viewpager – williamj949 Oct 04 '14 at 06:57
  • @goonedroid: that's not the case I'm looking for here. The only similarity is that the fragment has a viewpager. My viewpager's pages need to be replaced. – HukeLau_DABA Oct 04 '14 at 17:05

1 Answers1

0

I finally figured out a solution, not sure why this works because I thought an Activity's getSupportFragmentManager() returns the same fragment manager as its fragment's getFragmentManager().

Anyway, instead of getFragmentManager() in the fragments, use getActivity().getFragmentManager()

HukeLau_DABA
  • 2,384
  • 6
  • 33
  • 51