2

我需要刷新我的活动,一旦我点击我的标签活动回来。目前它只是显示以前的内容。我需要刷新我的活动,所以新内容可以在其后面加载。这是我添加TabActivity的代码。请帮忙。感谢您的反馈。在Android上刷新标签活动

private void setTabs() 
{ 
    addTab("Home", R.drawable.tab_home, OptionsActivity.class); 
    addTab("News", R.drawable.tab_search, JsonActivity.class); 
    addTab("Scores", R.drawable.tab_home, scores.class); 
    addTab("Video", R.drawable.tab_search, JsonActivity2.class); 
    addTab("Follow Us", R.drawable.tab_home, SAXParserActivity.class); 
    addTab("Socket", R.drawable.tab_search, socketAndroid.class); 
} 



private void addTab(String labelId, int drawableId, Class<?> c) 
{ 
    TabHost tabHost = getTabHost(); 
    Intent intent = new Intent(this, c); 
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); 
    TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
    title.setText(labelId); 
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
    icon.setImageResource(drawableId); 

    spec.setIndicator(tabIndicator); 
    spec.setContent(intent); 
    tabHost.addTab(spec); 

} 

回答

6

这是最后添加的代码...我添加了.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

TabHost tabHost = getTabHost(); 
Intent intent = new Intent(this, c).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

谢谢大家。

+0

尽管我会添加这样的内容:“如果已设置,并且正在启动的活动已在当前任务中运行,则不会启动该活动的新实例,而是关闭其上的所有其他活动,并且此Intent将作为新的Intent传递给(现在处于顶端)旧活动。“ - http://developer.android.com/reference/android/content/Intent.html – else

0

你试图更新什么类型的内容?如果您使用阵列适配器,则可以拨打notifyDataSetChanged()。或者,如果您可以通过其id属性来引用文本字段,则可以动态修改它们。

+0

谢谢Joel。我只是添加了addFlags(意图,FLAG_ACTIVITY_CLEAR_TOP),它很好用。这里是我的代码 – dhiku

+0

哦,我明白你想要做什么..这很好。 – Joel

1

将标志.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);添加到您的意图作为dhiko上面提到的,它会每次你选择标签时调用相关的活动。