Fragment嵌套Fragment之后,滑动超过2个Fragment再次进入之前的Fragment数据消失的问题

public class FragmentAdapter extends FragmentPagerAdapter {

    private FragmentManager fragmentManager;
    private List fragmentList;

    public FragmentAdapter(FragmentManager fm, FragmentManager fragmentManager) {
        super(fm);
        this.fragmentManager = fragmentManager;
    }

    public FragmentAdapter(FragmentManager fm, List fragmentList) {
        super(fm);
        this.fragmentManager = fm;
        this.fragmentList = fragmentList;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        fragment = fragmentList.get(position);
        Bundle bundle = new Bundle();
        bundle.putString("id", position + "");
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @NonNull
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container, position);
        fragmentManager.beginTransaction().show(fragment).commit();
        return fragment;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Fragment fragment = fragmentList.get(position);
        fragmentManager.beginTransaction().hide(fragment).commit();
    }
}

你可能感兴趣的:(Fragment嵌套Fragment之后,滑动超过2个Fragment再次进入之前的Fragment数据消失的问题)