我使用了 TabActivity 我有五个选项卡,在每个活动中都有数据库连接我想要如果我将一个选项卡移动到另一个选项卡活动不应该完成,所以如果我回来所以活动 onCreate() 方法不应该再次调用
我的代码如下
public class TabSample extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_main);
setTabs();
}
private void setTabs() {
addTab("", R.drawable.a, A.class);
addTab("", R.drawable.b, B.class);
addTab("", R.drawable.c, C.class);
addTab("", R.drawable.d, D.class);
addTab("", R.drawable.e, E.class);
}
private void addTab(String labelId, int drawableId, Class<?> c) {
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}