Android App 開發專案過程分享
http://ithelp.ithome.com.tw/ironman6/player/xq3da2/dev/1
資料庫
本專案會用到資料庫來存放資料,因此虛設計一個資料苦輔助類別,進行資料表的建立及異動更新使用。
專案 > New > Class > MyDBHelper
MyDBHelper.java
package tw.brad.android.apps.MyNotebook;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class MyDBHelper extends SQLiteOpenHelper {
private final String createTableSQL =
"CREATE TABLE IF NOT EXISTS notebook " +
"(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title TEXT, " +
"priority INTEGER, " +
"content TEXT, " +
"del TEXT, " +
"status TEXT)";
public MyDBHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(createTableSQL);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS notebook");
onCreate(db);
}
}