Avoid recreating same view when perform tab switching

后端 未结 6 586
一生所求
一生所求 2021-01-30 17:43

Current, I have 2 Fragments, which is switch-able through ActionBar\'s tab.

    getSupportActionBar().setNavigationMode(ActionBar.NAVIG         


        
6条回答
  •  情歌与酒
    2021-01-30 18:07

    I had the same problem, and tried to follow the suggestion in the error message. I tried the following code, and it worked for me.

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state)  {
         if (mMyView == null) {
             mMyView = new MyView(getActivity());
         } else {
             ((ViewGroup) mMyView.getParent()).removeView(mMyView);
         }
    
         return mPuzzleView; 
    }
    

提交回复
热议问题