views:

242

answers:

2

I have a code for populating content for tabs dynamically. First time it works ok, but when I want to replace tabs (and their content) with new content - tabs are changed but tabs' contents are not, how can I clear completely whole TabHost and replace with other content?

TabHost tabHost = getTabHost();
Intent intent;
TabHost.TabSpec spec;

tabHost.setCurrentTab(0);
tabHost.clearAllTabs();

int idx = 0;
for(Group g: c.getGroups()){
            intent = new Intent().setClass(this, GroupActivity.class);

            ItemLookup.createForGroup(idx).putToIntent(intent);

            spec = tabHost
                .newTabSpec("tab"+idx)
                .setIndicator(g.getTitle())
                .setContent(intent);
            tabHost.addTab(spec);
            idx++;
 }
 tabHost.setCurrentTab(0);
A: 

Call clearAllTabs() on the TabHost.

CommonsWare
I call it: tabHost.clearAllTabs();
Solvek
A: 

The problem was in reusing same tab tags for new tabs. I changed code for using random tab tags instead:

Random r = new Random();
...
spec = tabHost
.newTabSpec("tab"+r.nextInt())
    .setIndicator(g.getTitle())
    .setContent(intent);
Solvek