13

My application needs to update tab indicator dynamically, I'm trying to do this by invoke TabSpec.setIndicator(), but it doesn't work. Here is my code:

In onCreate method of TabActivity:

tabHost = getTabHost(); 
TabSpec tabSpec = tabHost.newTabSpec("abc");
tabSpec.setIndicator("helloabc");
tabSpec.setContent(new MyViewFactory());
tabHost.addTab(tabSpec);

Now I need to change tab indicator to another string, for example, "xyz"

TabSpec tabSpec = MyTabActivity.getTabSpec();
tabSpec.setIndicator("xyz");

But it doesn't work. So I'd like to know how to change tab indicator after it is added to the tabhost? Many thanks.

Solution

Thanks to @CommonsWare, I make it by using TabWidget.getChildAt, here is my code for your convenience:

TextView title = (TextView) tabHost.getTabWidget().getChildAt(tabId).findViewById(android.R.id.title)
title.setText("xyz");
ZelluX
  • 69,107
  • 19
  • 71
  • 104

3 Answers3

13

I apologize for my earlier incorrect answer, now deleted.

Try using getChildViewAt() on TabWidget.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
7

i managaed with getChildTabViewAt(tabId) instead of childviewAt(id) for multiple tab.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
chrish
  • 71
  • 1
  • 1
0

Try this:

 TextView title = (TextView) TabHost.getTabWidget().getChildTabViewAt(tabId).findViewById(android.R.id.title);
princepiero
  • 1,287
  • 3
  • 15
  • 28