[英]How to prevent starting the activity at the first tab in a TabActivity?
I have a TabActivity, which contains 4 activities. 我有一个TabActivity,其中包含4个活动。 My code sets the second tab as the current tab:
我的代码将第二个选项卡设置为当前选项卡:
public class MyTabActivity extends TabActivity {
TabHost tabHost = getTabHost();
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
TextView tabView;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Activity1.class);
spec = tabHost.newTabSpec("Tab 1");
spec.setContent(intent);
tabView = (TextView) inflater.inflate(R.layout.ff_tab_indicator, null);
tabView.setText("Tab 1");
spec.setIndicator(tabView);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Activity2.class);
spec = tabHost.newTabSpec("Tab 2");
spec.setContent(intent);
tabView = (TextView) inflater.inflate(R.layout.ff_tab_indicator, null);
tabView.setText("Tab 2");
spec.setIndicator(tabView);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Activity3.class);
spec = tabHost.newTabSpec("Tab 3");
spec.setContent(intent);
tabView = (TextView) inflater.inflate(R.layout.ff_tab_indicator, null);
tabView.setText("Tab 3");
spec.setIndicator(tabView);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Activity4.class);
spec = tabHost.newTabSpec("Tab 4");
spec.setContent(intent);
tabView = (TextView) inflater.inflate(R.layout.ff_tab_indicator, null);
tabView.setText("Tab 4");
spec.setIndicator(tabView);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
The problem is, when the MyTabActivity starts, it starts both activity in the first tab and the activity in the second tab. 问题是,当MyTabActivity启动时,它会启动第一个选项卡中的活动和第二个选项卡中的活动。 I just want it to start the activity in the second tab, since it is set to be the current tab.
我只是希望它在第二个选项卡中启动活动,因为它被设置为当前选项卡。 What should I do?
我该怎么办?
Thanks. 谢谢。
试试这个:
tabHost.setCurrentTab(0);
那么只需重新排序选项卡,以便默认成为第一个?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.