android tabwidget intent tabs refresh every hit

ε祈祈猫儿з 提交于 2019-12-03 06:18:41

问题


I want to create a tab using child tab having intents, so that when ever user click on tabs intents get refresh.

Every time user click on tab i want to refresh and called oncreate method of child intent tabs.

public class Tabs3 extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("list")
                .setContent(new Intent(this, List1.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("photo list")
                .setContent(new Intent(this, List8.class)));

        // This tab sets the intent flag so that it is recreated each time
        // the tab is clicked.
        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("destroy")
                .setContent(new Intent(this, Controls2.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    }
}

回答1:


Adding .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) fulfilled the desired thing.



来源:https://stackoverflow.com/questions/2370527/android-tabwidget-intent-tabs-refresh-every-hit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!