public class MainActivity extendsTabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // R.layout.main改成了R.layout.activity_main
import android.content.Intent;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TabHost;
import example.mystock2.tabActivity.record;
import example.mystock2.tabActivity.setting;
import example.mystock2.tabActivity.stock;
import example.mystock2.util.DBHelper;
public class MainActivity extendsTabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // R.layout.main改成了R.layout.activity_main
Resources res = getResources();
// 因為是TabActivity可以取得TabHost物件的實例
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, market.class);
.setIndicator("market", res.getDrawable(R.drawable.tab_icon1))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, stock.class);
.setIndicator("stock", res.getDrawable(R.drawable.tab_icon2))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, record.class);
.setIndicator("record", res.getDrawable(R.drawable.tab_icon3))
.setContent(intent);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("setting")
.setIndicator("setting", res.getDrawable(R.drawable.tab_icon4))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
//取得一個資料庫輔助類別的實例
DBHelper source = new DBHelper(this);
//使用這個輔助類別取得可讀寫的資料庫
SQLiteDatabase db = source.getWritableDatabase();
}
}