解决Fragment在Viepager中切换不保存状态的问题

在FragmentPagerAdapter中重写以下方法:

 1         @Override
 2         public Object instantiateItem(ViewGroup container, int position) {
 3             Fragment fragment = (Fragment) super.instantiateItem(container, position);
 4             fm.beginTransaction().show(fragment).commit();
 5 
 6             return fragment;
 7         }
 8 
 9         @Override
10         public void destroyItem(ViewGroup container, int position, Object object) {
11             Fragment fragment = (Fragment) object;
12             fm.beginTransaction().hide(fragment).commit();
13         }

 

你可能感兴趣的:(解决Fragment在Viepager中切换不保存状态的问题)