My codes like this:
public void removeTabForLogout(){
if (tabHost.getTabWidget().getChildCount()==4){
tabHost.setCurrentTab(0);
tabHost.clearAllTabs();
tabHost.addTab(getTab1());
tabHost.addTab(getTab2());
}
}
private TabSpec getTab1(){
if (mTab1==null){
mTab1= tabHost.newTabSpec("tab1")
.setIndicator(...).setContent(intentForTab1);
}
return mTab1;
}
private TabSpec getTab2(){
if (mTab1==null){
mTab1= tabHost.newTabSpec("tab2")
.setIndicator(...).setContent(intentForTab2);
}
return mTab2;
}
I have 4 tabs in TabHost: tab1, tab2, tab3, tab4 , when user logout i will remove tab3 and tab4, so i call the removeTabForLogout() , clear all tabs in tabHost and re-add the tab1 and tab2.
In android 1.5 and android 1.6, if current selected tab is tab1 when i call removeTabForLogout, there is a exception throw at tabHost.addTab(getTab1()):
ERROR/AndroidRuntime(205): java.lang.IllegalStateException: View com.android.internal.policy.impl.PhoneWindow$DecorView@437aba18 has already been added to the window manager.
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:125)
........
at android.widget.TabHost.setCurrentTab(TabHost.java:320)
at android.widget.TabHost.addTab(TabHost.java:210)
at aitao.mobile.android.actMain.removeTabForLogout(actMain.java:266)
But removeTabForLogout() works fine in android 2.0 and later version.
I can't find any usefull information on Google. Does any one can help me? Thanks very much!