android解决FragmentStatePagerAdapter 造成重新绘制fragment状态不保存的问题

参考地址:https://blog.csdn.net/liulinghuidage/article/details/52051693
页面摧毁重建 参考官文地址http://www.android-doc.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html
重写这两个方法
@Override
public Fragment instantiateItem(ViewGroup container, int position) {
    Fragment fragment = (Fragment) super.instantiateItem(container,
            position);
    fm.beginTransaction().show(fragment).commit();
    return fragment;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    // super.destroyItem(container, position, object);
    Fragment fragment = (Fragment) object;
    fm.beginTransaction().hide(fragment).commit();
}
//    @Override
//    public int getItemPosition(@NonNull Object object) {
//        Log.e("getItemPosition",object.toString());
//
//        return POSITION_NONE;
//    }

 

你可能感兴趣的:(android解决FragmentStatePagerAdapter 造成重新绘制fragment状态不保存的问题)