@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頁切換回來時列表又重新刷新的話就按照上面的方式寫就行了。