views:

308

answers:

2

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");
+1  A: 

I apologize for my earlier incorrect answer, now deleted.

Try using getChildViewAt() on TabWidget.

CommonsWare
A: 

Thanks Dude, your answer really helped me to come out the problem. -Ajj

Ajj_Dev