简体   繁体   English

选项卡更改时,TabActivity销毁每个选项卡的活动

[英]TabActivity destroy Activity of each tab when tab changed

Problem in TabActivity I have three tabs in my app and every one is different activity. TabActivity中的问题我的应用程序中有三个选项卡,每个选项卡都是不同的活动。 In the first tab I have a textfield and listview through which user search But after the search when the tab is changed by the user and come back again to The search tab then the list and textbox are cleared. 在第一个选项卡中,我有一个文本字段和listview,用户可以通过该字段进行搜索,但是在搜索后,当用户更改了选项卡并再次返回到“搜索”选项卡时,将清除列表和文本框。

But I want to be still populates. 但我想仍然是人口。 What tab bar do with activity destroy? 活动会破坏哪些标签栏? Stop? 停止? Pause? 暂停? I don't know Is there any way to do this Thanks. 我不知道有没有办法做到这一点谢谢。

public class MainTab extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab);
        TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);            

        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
        TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");

        /* TabSpec setIndicator() is used to set name for the tab. */
        /* TabSpec setContent() is used to set content for a particular tab. */
        firstTabSpec.setIndicator("",getResources().getDrawable(R.drawable.search)).setContent(new Intent(this,Search.class));
        secondTabSpec.setIndicator("",getResources().getDrawable(R.drawable.manager)).setContent(new Intent(this,Manager.class));
        thirdTabSpec.setIndicator("",getResources().getDrawable(R.drawable.settings)).setContent(new Intent(this,Settings.class));

        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
        tabHost.addTab(thirdTabSpec);
…………………

the code is same as normal tabbar required.... it will be difficult if we save the instance manually of every class i have a lot of data in the activities 该代码与所需的普通标签栏相同。...如果我们手动保存每个类的实例,将很困难,因为我在活动中有很多数据

Replace your following code, 替换您的以下代码,

TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");

with these, 用这些,

TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM