Fragments Not Working Correctly After Orientation Change

后端 未结 5 1253
失恋的感觉
失恋的感觉 2020-12-14 10:36

I am having a problem with Fragments and orientation change.

I have an application which has a MainActivity which handles the switching up

5条回答
  •  执笔经年
    2020-12-14 11:14

    I had more or less the same problem, but the solutions presented above did not seem to work out in my situation. Eventually I found the following solution:

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        if (mFragment == null) {
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.replace(android.R.id.content, mFragment, mTag); // Use replace iso add
        }
        else {
            ft.attach(mFragment);
        }
    }
    

提交回复
热议问题