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

前端 未结 5 1818
执笔经年
执笔经年 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:14

    I solved this by just looking up the fragment in the tab listener constructor.

    public class TabListener implements ActionBar.TabListener 
    {
        private Fragment fragment;
        private final SherlockFragmentActivity activity;
        private final String tag;
        private final Class clazz;
    
        public TabListener(SherlockFragmentActivity activity, String tag, Class clazz) 
        {
            this.activity = activity;
            this.tag = tag;
            this.clazz = clazz;
    
            FragmentManager manager = ((SherlockFragmentActivity) activity).getSupportFragmentManager();
            fragment = manager.findFragmentByTag(tag);
        }
    ...
    }
    

提交回复
热议问题