Fragment overlaps sometimes when switching tabs [duplicate]

天涯浪子 提交于 2019-12-04 05:39:58

As mentioned by StackOverflowed above this is an intermittent issue. I found a way of fixing this by writing my own code to remove any existing fragments before committing a new one. Below is my code:

        fragmentManager = getFragmentManager();
        ft = fragmentManager.beginTransaction();

        mbFragment = new SettingsManageBooksFragment();
        ft.replace(R.id.setting_detail_container2, mbFragment).commit();
        mImgFragmentTitle.setImageResource(R.drawable.manage_my_books);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.imageButtonSettingsManageBooks:

            if (mPurchaseHistory == true) {
                ft.remove(phFragment);

                Log.d(TAG, "REMOVING PURCHASE HISTORY FRAG");

            } else if (mAudio == true) {
                ft.remove(aFragment);

                Log.d(TAG, "REMOVING AUDIO FRAG");
            } else if (mRestore == true) {
                ft.remove(rFragment);

                Log.d(TAG, "REMOVING RESTORE FRAG");
            } else if (mCopyright == true) {
                ft.remove(cFragment);

                Log.d(TAG, "REMOVING COPYRIGHT FRAG");
            } else if (mAbout == true) {
                ft.remove(abFragment);

                Log.d(TAG, "REMOVING ABOUT FRAG");
            }
            ft = fragmentManager.beginTransaction();
            mbFragment = new SettingsManageBooksFragment();
            ft.replace(R.id.setting_detail_container2, mbFragment).commit();
            mImgFragmentTitle.setImageResource(R.drawable.manage_my_books);
            mManageBooks = true;
            mPurchaseHistory = false;
            mAudio = false;
            mRestore = false;
            mCopyright = false;
            mAbout = false;

            break;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!