Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify tab indicator dynamically in Android

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");
like image 427
ZelluX Avatar asked May 29 '10 16:05

ZelluX


1 Answers

I apologize for my earlier incorrect answer, now deleted.

Try using getChildViewAt() on TabWidget.

like image 173
CommonsWare Avatar answered Oct 27 '22 19:10

CommonsWare