Android onNavigationDrawerItemSelected导致setContentView引发异常

时间:2015-05-27 13:57:33

标签: android android-fragments navigation-drawer fragmentmanager

我正在尝试使用导航抽屉创建活动。 起初它有这个//a public function that the container uses to pass in values for the labels function public_Labels(label1, label2, label3, label4, label5, label6, label7){ t1.innerText = label1; t2.innerText = label2; t3.innerText = label3; t4.innerText = label4; t5.innerText = label5; t6.innerText = label6; t7.innerText = label7; } //a public function that the container uses to pass in values for the card containers function public_Contents(contents1, contents2, contents3, contents4, contents5, contents6, contents7){ t1Contents.innerHTML = contents1; t2Contents.innerHTML = contents2; t3Contents.innerHTML = contents3; t4Contents.innerHTML = contents4; t5Contents.innerHTML = contents5; t6Contents.innerHTML = contents6; t7Contents.innerHTML = contents7; init(); } //sets the default display to tab 1 function init(){ tabContents.innerHTML = t1Contents.innerHTML; } //this is the tab switching function var currentTab; var tabBase; var firstFlag = true; function changeTabs(){ if(firstFlag == true){ currentTab = t1; tabBase = t1base; firstFlag = false; } if(window.event.srcElement.className == 'tab'){ currentTab.className = 'tab'; tabBase.style.backgroundColor = 'white'; currentTab = window.event.srcElement; tabBaseID = currentTab.id + 'base'; tabContentID = currentTab.id + 'Contents'; tabBase = document.all(tabBaseID); tabContent = document.all(tabContentID); currentTab.className = 'selTab'; tabBase.style.backgroundColor = ''; tabContents.innerHTML = tabContent.innerHTML; } } 方法,它运行良好:

onNavigationDrawerItemSelected

MainFragments.SOME_FRAGMENT的上述索引为1,因此代码从未尝试在启动时创建片段。

之后我将方法改为:

 @Override
    public void onNavigationDrawerItemSelected(final int position)
    {
        Fragment f = null;
        FragmentManager fragmentManager = getSupportFragmentManager();
        if (position == MainFragments.SOME_FRAGMENT.ordinal())
        {
            f = new SomeFragment();
            TabsFragmentUtils.replaceFragmentInContainer(fragmentManager, f, true);
        }

    }

现在MainFragments.MAIN_FRAGMENT是索引0,我看到这段代码试图运行并替换容器,然后我得到一个例外: @Override public void onNavigationDrawerItemSelected(final int position) { Fragment f = null; FragmentManager fragmentManager = getSupportFragmentManager(); if (position == MainFragments.MAIN_FRAGMENT.ordinal()) { f = new MainFragment(); } else if (position == MainFragments.SOME_FRAGMENT.ordinal()) { f = new SomeFragment(); } TabsFragmentUtils.replaceFragmentInContainer(fragmentManager, f, true); } (可能是导航抽屉)由Error inflating class fragment引起

经过调试后,我意识到代码没有通过正在初始化片段标签的Recursive entry to executePendingTransaction MainFragemnt方法。

可以做些什么呢?

0 个答案:

没有答案