I am very new to android programming. I want to use SQLiteOpenHelper class to do some database operations. Here is my SqliteController class that extends SQLiteOpenHelper:
public class SqliteController extends SQLiteOpenHelper {
Context context;
public SqliteController(Context context) {
super(context, "sectionsDB", null, 1);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
String query;
query = "CREATE TABLE Sections ( chapterName TEXT, sectionName TEXT, body TEXT)";
db.execSQL(query);
Log.i("tablecreation", "table created");
}
}
(I have just mentioned the part that I have problem with) in my main activity I have created instance of above class in onCreate method of activity like this:
SqliteController controller = new SqliteController(this);
I want to populate database by reading from xml file once in onCreate method of SqliteController so after newing SqliteController in main activity I don't want to do any operation with database. If I add controller.getWritableDatabase();
it seems that I have some operations to do with it but all I do is in SqliteController class. Any suggestion?
You can add something like this:
SqliteController controller = new SqliteController(this);
controller.getWritableDatabase();