ViewPage + Fragment 防止Fragment 重复加载问题

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.frg_document, container, false);
            initView();  //初始化要放这儿
        }
        ViewGroup parent = (ViewGroup) mRootView.getParent();
        if (parent != null) {
            parent.removeView(mRootView);
        }
        return mRootView;
    }

如果你initView()方法中有列表刷新数据的方法,那么为了避免tab页切换回来时列表又重新刷新的话就按照上面的方式写就行了。

原文地址:https://www.cnblogs.com/woaixingxing/p/6825241.html