我的Android應用程序正在使用FragmentTabHost並具有4個選項卡A,B,C,D。 我在標籤A中帶有A1片段,並且我導航到標籤A中的第二個片段A2, 然後我切換到標籤B,然後切換回標籤A.現在我單擊後面的按鈕,它將調用popBackStack()方法,我碰到說IllegalStateException Fragment A1已經添加。 你能幫忙嗎? 這是我以前在主標籤活動來創建標籤中的代碼,Android FragmentTabHost popBackStack()導致IllegalStateException已添加片段
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("profile").setIndicator("Profile"),
ProfileFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("friends").setIndicator("Friends"),
FriendsFragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("notifications").setIndicator(
"Notifications"), NotificationFragment.class, null);
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabID) {
mTabHost.clearFocus();
}
});
和我用這個代碼來處理返回按鈕按下,FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack();
請發佈您的代碼! – mmlooloo 2014-09-28 13:04:58
我剛剛更新了我的帖子。謝謝 – kenvu 2014-09-28 14:50:59