-3

私はAndroidプログラミングに非常に慣れていません。SQLiteOpenHelper クラスを使用してデータベース操作を実行したいと考えています。SQLiteOpenHelper を拡張する私の SqliteController クラスは次のとおりです。

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");
}
}

(私が問題を抱えている部分について言及したばかりです)私のメインアクティビティでは、次のようなアクティビティの onCreate メソッドで上記のクラスのインスタンスを作成しました:

SqliteController controller = new SqliteController(this);

SqliteController の onCreate メソッドで一度 xml ファイルから読み取ってデータベースにデータを入力したいので、メイン アクティビティで SqliteController を新規作成した後、データベースを操作したくありません。追加controller.getWritableDatabase();すると、それを行う操作がいくつかあるようですが、私が行うのは SqliteController クラスだけです。なにか提案を?

4

1 に答える 1