E-Madd
E-Madd

Reputation: 4582

ViewPager: Adapter views not restoring when going back

Here's my hierarchy:

CoordinatorLayout
- AppBarLayout
    - CollapsingToolbarLayout
- NestedScrollView
    - FrameLayout (contentFrame)
        - Container Fragment
            - ViewPager
                - Recycler(List) Fragment
                - Map Fragment
            - TabLayout

The Container Fragment shows a tabbed interface of two fragments: List and Map. Location data is listed and mapped, respectively. Selecting a location replaces the contentFrame fragment with a detail of the location data.

All of this is fine until I click the back button and return to the Container Fragment: the views that should be provided by the adapter are not restored and only the tabs are visible on the screen. I've tried stepping through the lifecycles of every fragment involved and have read documentation until my eyes have gone crossed. What could be the reason this is happening?

Upvotes: 0

Views: 270

Answers (1)

luca992
luca992

Reputation: 1593

If you are displaying a fragment within a fragment you should be using the child fragment manager. So you should be using the child fragment manager for your viewpager:

getChildFragmentManager() 

instead of

getFragmentManager() 

Are you doing that? hard to know without the code.

But sounds like it may be your problem

Upvotes: 1

Related Questions