Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed android android

Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed


I had the same issue. Changing the parent class of my PageAdapter from android.support.v4.app.FragmentPagerAdapter to android.support.v4.app.FragmentStatePagerAdapter solve my ViewPager display issue on "second time"!


I managed to solve this by replacing getFragmentManager() with getChildFragmentManager() in the parent fragment. This parent fragment was instancing an android.support.v4.app.FragmentPagerAdapter in order to contain pageable (slideable) fragments, which requires a fragment manager in the constructor. To this constructor I passed the return value of getChildFragmentManager().

hackbod's link was key (https://developer.android.com/about/versions/android-4.2.html#NestedFragments), which was found in this post Fragments within Fragments

To nest a fragment, simply call getChildFragmentManager() on the Fragment in which you want to add a fragment. This returns a FragmentManager that you can use like you normally do from the top-level activity to create fragment transactions.


for me i had to call this on my viewpager:

myViewPager.setSaveFromParentEnabled(false);

I had the issue where the viewpager was not refreshing and all i saw was a blank white screen where the fragments should be. I was passing in getChildFragmentManager but it did not help.