Android Action Bar Tab with scrollview made duplicate view after orientation change

前端 未结 5 1842
执笔经年
执笔经年 2021-01-04 10:52

I have a very simple code where I use Action Bar with tab fragments. It works fine after load, but after orientation change it goes crazy. The old fragment also visible (why

5条回答
  •  [愿得一人]
    2021-01-04 11:04

    public void onTabSelected(Tab tab, FragmentTransaction ft)
        {
            // Check if the fragment is already initialized
            if (mFragment == null)
            {
                if(ft.findFragmentById(android.R.id.content) == null){
                // If not, instantiate and add it to the activity
                mFragment = Fragment.instantiate(mActivity, mClass.getName());
                ft.add(android.R.id.content, mFragment, mTag);
                }
            } else
            {
                // If it exists, simply attach it in order to show it
                ft.attach(mFragment);
            }
    
        }
    

    Something like that, because your problem is that your adding the same fragment twice, we just have to find where...

提交回复
热议问题