我正在尝试将片段添加到后台堆栈,但它不起作用,我不断收到: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){
}
}