开发者

TabHost remove all content activities

开发者 https://www.devze.com 2022-12-29 11:08 出处:网络
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,

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号