Tab Content Disappeared After Change Page
I have a weird issue with my Tab (TabHost or TabContent) in my Fragment that contains a ViewPager. The problem is that when I change the page, then I turn back to the fragment with
Solution 1:
I had the same problem. In your TabFragment class (GameTabFragment) replace getFragmentManager with getChildFragmentManager.
Instead of: adapter = new TabPagerAdapter(this.getFragmentManager());
Use this: adapter = new TabPagerAdapter(this.getChildFragmentManager());
This should fix it.
Solution 2:
I have 3 tabs and experienced same issue. I used below code and problem fixed.
pager.setOffscreenPageLimit(2);
Solution 3:
In PagerFragment 's onResume() add this:
@OverridepublicvoidonResume() {
super.onResume();
for (Fragment fragment : getFragmentManager().getFragments()) {
if (fragment instanceof Tab1Fragment || fragment instanceof Tab2Fragment) {
FragmentTransactionft= getFragmentManager().beginTransaction();
ft.detach(fragment);
ft.attach(fragment);
ft.commit();
}
}
}
Solution 4:
It may be too late, but I was stack with the same issue for hours even of all of the above answers, so I ended up making my own one which consists of:
Using
getChildFragmentManager()
to commit the firsttransaction
(the commit you usually do in the root Fragment which is one of yourviewpager
'stabs
)getFragmentManager()
to commit the rest of transactions (used to replace the nested fragments).
This might be an answer to this question IllegalArgumentException: No view found for id for fragment --- ViewPager in ViewPager too.
Hope this is going to help someone-else too!
Post a Comment for "Tab Content Disappeared After Change Page"