Updating Android Tab Icons

Posted by lnediger on Stack Overflow See other posts from Stack Overflow or by lnediger
Published on 2008-08-31T14:36:11Z Indexed on 2010/06/10 12:32 UTC
Read the original article Hit count: 257

Filed under:

I have an activity which has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set an icon to be displayed in the tab header.

The TabSpecs are created in this way within a setupTabs() method which loops to create the appropriate number of tabs:

TabSpec ts = mTabs.newTabSpec("tab");
ts.setIndicator("TabTitle", iconResource);

ts.setContent(new TabHost.TabContentFactory(
{
    public View createTabContent(String tag)
    {
        ...	
    }   		 
});
mTabs.addTab(ts);

There are a couple instances where I want to be able to change the icon which is displayed in each tab during the execution of my program. Currently I am deleting all the tabs, and calling the above code again to re-create them.

mTabs.getTabWidget().removeAllViews();
mTabs.clearAllTabs(true);
setupTabs();

Is there a way to replace the icon that is being displayed without deleting and re-creating all of the tabs?

© Stack Overflow or respective owner

Related posts about android