Question

I have created three tabs in TabActivity onCreate.

How can I hide one tab at runtime?

Was it helpful?

Solution

To hide the tab you must remove it from the TabWidget. Just setting INVISIBLE is not enough. So, to hide the tab:

tab = getTabHost().getTabWidget().getChildTabViewAt(tabPosition);
getTabHost().getTabWidget().removeViewAt(tabPosition);

And to show that tab again:

getTabHost().getTabWidget().addView(tab, tabPosition);

OTHER TIPS

For Removing the particular tab from tabwidget :

tab = tabhost.getTabWidget().getChildTabViewAt(tabPosition); tabhost.getTabWidget().removeView(tab);

and for adding it back to tabwidget :

 tabhost.getTabWidget().addView(tab);

OR

 tabhost.getTabWidget().addView(tab,tabPosition);

If you want to hide the tabWidget you can do so by setting the visibility to GONE/INVISIBLE like:

getTabWidget().setVisibility(TabWidget.GONE);   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top