<myfragment>目前不在FragmentManager Android </myfragment>中

时间:2013-06-17 21:13:32

标签: android fragment add commit fragmenttransaction

我知道要解决它的例外,我需要像这样写:

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中

0 个答案:

没有答案