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. 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.
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 instanc开发者_如何学JAVAe 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");
精彩评论