ViewPage Fragment disappear when reload again

前端 未结 5 1251
执笔经年
执笔经年 2021-02-06 05:20

The following is layout

test.xml





        
5条回答
  •  不知归路
    2021-02-06 05:36

    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();
            }
        }
    }
    

提交回复
热议问题