必要な 2 つのテーブル (user_table と prod_table) を使用してデータベース クラスをセットアップしています。
このガイドに従う: http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android
これはちょっと問題ないように見えますが、典型的な「getConnection()」メソッドをどのように行うかについては決して述べていません。たとえば、私はアクティビティの中にいて、insertUserRow() をしたいのですが、SQLiteOpenConnection db とユーザー オブジェクトを渡す必要があります。次のように、各ヘルパーでシングルトンを作成しました。
public class UserEdbHelper extends SQLiteOpenHelper {
static final String dbName = "edb";
static final String userTable = "user_table";
private static UserEdbHelper mInstance = null;
/* --- user_table columns --- */
static Context appContext;
UserEdbHelper(Context context) {
super(context, dbName, null, 33);
this.appContext = context;
}
public static UserEdbHelper getInstance(Context ctx) {
if (mInstance == null) {
mInstance = new UserEdbHelper(ctx.getApplicationContext());
}
return mInstance;
}
また、次のことを行うように指示した別の例をフォローアップしようとしました。
public class AppCore extends Application{
// create the 2 helpers that creates the respective tables
public static UserEdbHelper userHelper;
public static ProductEdbHelper productHelper;
public static void init(Context context )
{
// this is supposed to instantiate the helpers or what? what does this do?
userHelper = new UserEdbHelper(context);
productHelper = new ProductEdbHelper(context);
}
}
心に欠けているものがあります。
また、ヘルパーごとに UserEdbHelper と ProductEdbHelper の 2 つのクラスを作成しましたが、正しいですか? これらはそれぞれ独自のテーブルを作成し、独自のメソッドを持っています。(基本的には、上で追加したリンクと同じ構造です。そこで確認できます)
属性の 1 つは「dbName」です。その属性を両方のクラスに追加する必要がありますか、それとも 1 つだけに追加する必要がありますか?
ちょっと失った:(
少しでもお役に立てれば幸いです、
前もって感謝します、
マリアーノ。