Tôi có một TabActivity, trong đó có 4 hoạt động. Mã của tôi đặt tab thứ hai là tab hiện tại:Làm thế nào để ngăn chặn bắt đầu hoạt động tại tab đầu tiên trong TabActivity?
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);
}
Vấn đề là, khi MyTabActivity bắt đầu, nó bắt đầu cả hoạt động trong tab đầu tiên và hoạt động trong tab thứ hai. Tôi chỉ muốn nó bắt đầu hoạt động trong tab thứ hai, vì nó được đặt làm tab hiện tại. Tôi nên làm gì?
Cảm ơn.
@kknight: Bên cạnh không sử dụng hoạt động như nội dung của tab? – CommonsWare
@kknight: Bạn đang cố gắng làm gì? – Macarse
Tôi chỉ muốn đặt tab 2 làm tab mặc định. Khi hoạt động tab bắt đầu, chỉ hoạt động trong tab 2 mới bắt đầu. Hiện tại, Android bắt đầu cả hoạt động trong tab 1 và hoạt động trong tab 2, nếu tôi đặt tab 2 làm tab hiện tại mặc định. – user256239