我用 SQLite 做了一个测验,但它很混乱,我不明白如何在代码中存储问题,因为我只想显示 15 个问题,但我想总共有 100 个问题。我尝试用 SQLite 存储它们,但我只是不明白它是如何工作的。私有 SQLiteDatabase 数据库;public QuizDbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION);}@Overridepublic void onCreate(SQLiteDatabase db) { this.db = db; final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " + QuestionsTable.TABLE_NAME + " ( " + QuestionsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + QuestionsTable.COLUMN_QUESTION + " TEXT, " + QuestionsTable.COLUMN_OPTION1 + " TEXT, " + QuestionsTable.COLUMN_OPTION2 + " TEXT, " + QuestionsTable.COLUMN_OPTION3 + " TEXT, " + QuestionsTable.COLUMN_OPTION4 + " TEXT, " + QuestionsTable.COLUMN_ANSWER_NR + " INTEGER" + ")"; db.execSQL(SQL_CREATE_QUESTIONS_TABLE); fillQuestionsTable();}@Overridepublic void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { db.execSQL("DROP TABLE IF EXISTS " + QuestionsTable.TABLE_NAME); onCreate(db);}private void fillQuestionsTable(){ Question q1 = new Question("Who almost killed Thanos in the Final Battle?", "Captain America", "Iron Man", "Captain America", "Scarlet Witch",4); addQuestion(q1); etc...
添加回答
举报
0/150
提交
取消