Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed
We got around this by re-implementing the view pager items as standard views rather than fragments and changing the adapter accordingly.
Viewpager empty when opened second time
Do not use getActivity().getSupportFragmentManager()
to get fragment manager for FragmentPagerAdapter
. Just use getChildFragmentManager
method instead.
Android fragment empty in viewpager when I come back in
Use this code
adapter = new MyPagerAdapter(getChildFragmentManager());
instead of
adapter = new MyPagerAdapter(getFragmentManager());
Viewpager Fragments turning blank
I had a problem like that
try this
mPager.setAdapter(new BasePagerAdapter(getChildFragmentManager(), getResources()));
you probably have this
mPager.setAdapter(new BasePagerAdapter(getFragmentManager(), getResources()));
EDIT:
and in your BasePagerAdapter extend FragmentStatePagerAdapter
public class BasePagerAdapter extends FragmentStatePagerAdapter {
ViewPager inside a fragment is empty when navigating back from another fragment
Ok, I figured that out. The problem with passing the childFragmentManager was because child fragment doesn't contain the container whose fragment(s) are to be replaced, so the app crashed with "No view found..." exception. However, when replacing the fragment, if I use the parent's fragmentManager, then all works fine! So, instead of fragment.fragmentManager!!.beginTransaction() I now call fragment.parentFragment!!.fragmentManager!!.beginTransaction(). In case someone will face the same problem.
Tabs show blank fragment on returning to fragment second time
Change
mAdapter = new TabsPagerAdapter(myContext.getSupportFragmentManager());
To
mAdapter = new TabsPagerAdapter(getChildFragmentManager());
Related Topics
How to Use Tools:Overridelibrary in a Build.Gradle File
How to Read "Adb Shell Dumpsys Alarm" Output
How to Maintain the Immersive Mode in Dialogs
How to Set Android_Home Path in Ubuntu
Eclipse Reports Rendering Library More Recent Than Adt Plug-In
How to Loop Through Dynamic JSON String Recursively in Android
Which Architecture Patterns Are Used on Android
"Failure Delivering Result " - Onactivityforresult
How to Use Autocompletetextview and Populate It with Data from a Web API
Passing String Array Between Two Class in Android Application
How to Design Any Screen Size and - Density in Android(Multi Screen for Mobiles in Android)
Design Layout for Multiple Screens
Handle Button Click Inside a Row in Recyclerview
Why Was "Avoid Enums Where You Only Need Ints" Removed from Android's Performance Tips
Actionbaractivity Cannot Resolve a Symbol
Android: Remove All the Previous Activities from the Back Stack