FragmentTransaction不允许添加到Backstack中

时间:2012-12-28 02:34:31

标签: android fragment back-stack

我正在尝试向backstack添加片段,但它无法正常工作,我一直得到:java.lang.IllegalStateException: This FragmentTransaction is not allowed to be added to the back stack.

我正在使用actionbar sherlock,在我的主要活动中,我会听取标签

private class MyTabListener implements ActionBar.TabListener{

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft){

//to hide keyboard
            final InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(myView.getWindowToken(), 0);
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);



            if(tab.equals(tabData))
            {
                ft.setCustomAnimations(R.anim.animation_fragment_out, R.anim.animation_fragment_switch);

                ft.replace(android.R.id.content, dataFrag);
                imm.hideSoftInputFromWindow(myView.getWindowToken(), 0);
                //ft.setTransition(R.anim.animation_fragment_switch);

                curTab = tabData;
                ft.addToBackStack(null);
                //ft.commit();
                //ft.commit();

            }
            else if(tab.equals(tabComp))//new competition
            {
                ft.setCustomAnimations(R.anim.animation_fragment_out, R.anim.animation_fragment_switch);

                ft.replace(android.R.id.content, teamsFrag);

                //ft.setTransition(R.anim.animation_fragment_switch);
                //ft.commit();

                actionBar.removeTab(tabData);
                actionBar.removeTab(tabComp);
                actionBar.addTab(tabMatches);
                actionBar.addTab(tabRed);
                actionBar.addTab(tabBlue);

                curTab = tabComp;
                ft.addToBackStack(null);
            }



        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft){

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft){
        }

    }

0 个答案:

没有答案