我已经用dbhelper java类中的手动输入制作了一个测验应用程序。因为我想添加更多问题,所以我认为使用已经存在的现有SQLite数据库会更容易。我应该在dbhelper类中进行哪些更改?
.....
private void fillQuestionTable(){
soal q1 = new soal("A is correct", "A", "B","C", 1);
addSoal(q1);
soal q2 = new soal("B is correct", "A", "B","C", 2);
addSoal(q2);
soal q3 = new soal("C is correct", "A", "B","C", 3);
addSoal(q3);
}
private void addSoal(soal soal){
ContentValues cv = new ContentValues();
cv.put(KuisEntry.KEY_QUES, soal.getQuestion());
cv.put(KuisEntry.KEY_OPTA, soal.getOpta());
cv.put(KuisEntry.KEY_OPTB, soal.getOptb());
cv.put(KuisEntry.KEY_OPTC, soal.getOptc());
cv.put(KuisEntry.KEY_ANSWER, soal.getAnswer());
db.insert(KuisEntry.TABLE_QUEST, null, cv);
}
public List<soal> getAllQuestion(){
List<soal> questionList = new ArrayList<>();
db = getReadableDatabase();
Cursor c = db.rawQuery(" SELECT * FROM " + KuisEntry.TABLE_QUEST, null);
if(c.moveToFirst()){
do{
soal soal = new soal();
soal.setQuestion(c.getString(c.getColumnIndex(KuisEntry.KEY_QUES)));
soal.setOpta(c.getString(c.getColumnIndex(KuisEntry.KEY_OPTA)));
soal.setOptb(c.getString(c.getColumnIndex(KuisEntry.KEY_OPTB)));
soal.setOptc(c.getString(c.getColumnIndex(KuisEntry.KEY_OPTC)));
soal.setAnswer(c.getInt(c.getColumnIndex(KuisEntry.KEY_ANSWER)));
questionList.add(soal);
}while(c.moveToNext());
}
c.close();
return questionList;
}