14

In a TabHost widget, I can create a new tab with its content (Intent) using TabHost.addTab(TabHost.TabSpec tabSpec).

We can remove all tabs we created by calling clearAllTabs(), but I can't figure out how to remove the tab or just replace the content (Intent) inside the tab with new Intent.

so what I need something like removeTab(int index)

Anwar Chandra
  • 8,538
  • 9
  • 45
  • 61

2 Answers2

25

Much Easier:

 tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(3));
vinay Maneti
  • 1,447
  • 1
  • 23
  • 31
2red13
  • 11,197
  • 8
  • 40
  • 52
13

Actually, clearAllTabs does that :

public void clearAllTabs() {
  mTabWidget.removeAllViews();
  initTabHost();
  mTabContent.removeAllViews();
  mTabSpecs.clear();
  requestLayout();
  invalidate();
}

And the method removeAllViews comes from the class ViewGroup. Luckily, ViewGroup does have methods to remove only one view :

  • removeView(View view)
  • removeViewAt(int index)
  • removeViewInLayout(View view)

Knowing that, I would recommend to subclass TabWidget and TabHost to add the behaviour you need. Maybe there is an easier way but that's the only one I can think of. Good luck

Rup
  • 33,765
  • 9
  • 83
  • 112
Sephy
  • 50,022
  • 30
  • 123
  • 131