I've started to develop a quiz application (multiple and single choice) for android. The reason why I chose the SqliteAssetHelper library is, that I want a prepopulated database. I've created a sqlite database with 2 tables (question & answer).
With the following method in my database class I'm getting the question items:
public Cursor getQuestionItems() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLES.QUESTION);
Cursor questionCursor = qb.query(db, null, null, null, null, null, null);
return questionCursor;
}
In the main class (in onCreate) I'm creating question objects and add them to the arraylist:
Cursor questionCursor = db.getQuestionItems();
while (questionCursor.moveToNext()) {
Question question = new Question();
question.setId(
questionCursor.getString(questionCursor.getColumnIndexOrThrow(MyDatabase.QuestionColumns.ID)));
question.setQuestiontext(questionCursor
.getString(questionCursor.getColumnIndexOrThrow(MyDatabase.QuestionColumns.QUESTIONTEXT)));
question.setQuestiontype(questionCursor
.getInt(questionCursor.getColumnIndexOrThrow(MyDatabase.QuestionColumns.QUESTIONTYPE)));
questionList.add(question);
}
questionCursor.close();
I'm doing the same also for the answer items. Now I want to show a view with a question and the possible answers (for example 4 answers). If the user clicks on the "next"-button the next question with the answers should be displayed.
How can I achieve this efficiently? Is it at all necessary to create question and answer items? I'm not sure if this is the right way.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire