我有一个TabActivity,其中包含4个活动。我的代码将第二个选项卡设置为当前选项卡:
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);
}
问题是,当MyTabActivity启动时,它会启动第一个选项卡中的活动和第二个选项卡中的活动。我只是希望它在第二个选项卡中启动活动,因为它被设置为当前选项卡。我该怎么办?
感谢。
答案 0 :(得分:3)
试试这个:
tabHost.setCurrentTab(0);
答案 1 :(得分:1)
如何重新排序选项卡以使默认值成为第一个?