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 = get开发者_StackOverflow社区TabHost();
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);
Call clearAllTabs()
on the TabHost
.
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);
精彩评论