I'm having trouble implementing a design based on multiple ViewPagers.
At a high level, I have a FragmentActivity with only FrameLayout as the content. I have 3 different fragments that I want to display. All 3 are full-screen, and only 1 will be used at a time.
Fragment 1 is the main fragment with some TextViews and ImageViews. Fragment 2 has a ViewPager and a FragmentPagerAdapter, which passes it a few simple snippets. Fragment 3 has a ViewPager and FragmentPagerAdapter, which passes it a few simple fragments (other than fragment 2)
In my FragmentActivity onCreate (), I get a FragmentManager and start a transaction to replace everything in my FrameLayout with a new instance of fragment 2.
At this point, everything is working as expected. My ViewPager in Fragment 2 works fine.
Now I have a menu option that replaces fragment 2 in my FrameLayout with a new instance of fragment 3. This also works great.
The problem occurs when I try to return Fragment 2 to FrameLayout with a different transaction replacement. I see that my PagerIndicater is at the top, but my pages are blank.
I tried just creating a new instance of my fragment 2 and invoking a replacement transaction. I also tried to set the tag on my snippets when I call the replacement and add the findFragmentByTag check before the replacement instead of creating a new instance. Both gave me the same blank page result after my second replacement.
For reference, My first design was just FragmentActivity with ViewPager and ViewIndicater. I had only fragment 2 and fragment 3 from my description above and a menu item to switch between them. To switch, I had two different FragmentPagerAdapters that were defined and just called ViewPager.setAdapter to set the selected FragmentPagerAdapter. This works fine, but now I need a new top-level snippet that doesn't use ViewPager at all. That's why I decided to move my ViewPagers to my own snippets. My idea is that I just swap my fragments for FrameLayout.
I donโt have my code in front of me right now, so I canโt publish it, but I will add the code to my question tomorrow to facilitate the answers.
android android-fragments android-viewpager fragmentpageradapter android-nested-fragment
brockoli
source share