这是一个片段,我实例这样
From a fragment I instantiate this way
fmdata = new FileManagerData(getActivity());
下面的类。我不明白为什么的onCreate()将不会调用和我的数据库还没有生成。
the following class. I don't understand why onCreate() is not called and my database does not get created.
public class FileManagerData {
public static final String TAG = FileManagerData.class.getSimpleName();;
Context context;
DBHelper dbHelper;
public FileManagerData (Context context){
this.context = context;
dbHelper = new DBHelper();
}
private class DBHelper extends SQLiteOpenHelper{
private static final String DB_NAME = "filename.db";
private static final String DB_SQL = "filename.sql";
private static final int DB_VERSION = 1; // internal number
public DBHelper() {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// this is NEVER called and my DB does not exist yet
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
修改的:诀窍是数据库必须使用(读取或写入),这样的onCreate()被调用
EDIT: The trick is that the database has to be used (to read or write) so onCreate() get called.
在的onCreate
方法会后的第一次访问数据库调用。做一个查询到DB和的onCreate
将被调用。
The onCreate
method will be called after first access to the DB. Make a query to the DB and onCreate
will be invoked.
上一篇:在点击的EditText框,然后不打开手机的键盘这塞纳里奥如何实现的里奥、如何实现、塞纳、键盘
下一篇:安卓:编程 - 如何打开电子邮件的邮件帐户(例如Gmail中)接受。像黑莓有ViewListener接口,它有open()和close()方法帐户、接口、电子邮件、邮件