2

我知道要解决它异常我需要这样写:

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
TabInfo currentTabInfo = getCurrentTabInfo();
Fragment currentFragment = currentTabInfo.mTabFragments
                            .peek();
currentTabInfo.detachFragment(ft, currentFragment);
currentTabInfo.attachFragment(ft, fragment);
currentTabInfo.detachFragment(ft, fragment);
ft.commit();
.........

    protected void attachFragment(FragmentTransaction ft, Fragment fragment) {
        if (mAbstractTabActivity.mFragmentsWasAdded.contains(fragment)) {
            ft.attach(fragment);
        } else {
            ft.add(R.id.fragment_container, fragment, String.valueOf(mTag));
            mAbstractTabActivity.mFragmentsWasAdded.add(fragment);
        }
    }
        protected void detachFragment(FragmentTransaction ft, Fragment fragment) {
            if (!fragment.isDetached()) {
                ft.detach(fragment);
            }
        }

但是当我攻击/分离我的片段时,这个片段开始执行。所以我的问题是如何在不开始执行的情况下将片段添加到 FragmentManager ???

4

0 回答 0