Tab content disappeared after change page

徘徊边缘 提交于 2019-12-03 03:33:49

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.

I have 3 tabs and experienced same issue. I used below code and problem fixed.

pager.setOffscreenPageLimit(2);

In PagerFragment 's onResume() add this:

@Override
public void onResume() {
    super.onResume();

    for (Fragment fragment : getFragmentManager().getFragments()) {
        if (fragment instanceof Tab1Fragment || fragment instanceof Tab2Fragment) {
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.detach(fragment);
            ft.attach(fragment);
            ft.commit();
        }
    }
}
hzitoun

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 first transaction (the commit you usually do in the root Fragment which is one of your viewpager's tabs)
  • 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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!