FragmentTabHost切换Fragment时避免onCr
作者:
梦沉薇露 | 来源:发表于
2017-04-28 16:46 被阅读38次private View rootView;//缓存Fragment view
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(rootView==null){
rootView=inflater.inflate(R.layout.tab_fragment, null);
}
//缓存的rootView需要判断是否已经被加过parent, 如果有parent需要从parent删除,要不然会发生这个rootview已经有parent的错误。
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null) {
parent.removeView(rootView);
}
return rootView;
}
本文标题:FragmentTabHost切换Fragment时避免onCr
本文链接:https://www.haomeiwen.com/subject/gzhazttx.html
网友评论