i'm making an android quiz app. there are have one question an four answers, one of four is true. when user choose wrong answer the game is end, so i want to insert this question and the true answer to database to show it in the listview. but it so difficult with me, please help me some codes. this is my choose answer method:
private void onOptionSelected(String option){
if(!isGamePaused && !isGameEnded) {
ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
correct += 1;
remainingTime = mySecondsPassed;
totalPoints += remainingTime * pointsPerRemainingSecond;
totalPoints += pointsPerCorrectAnswer;
Toast.makeText(PlayGame.this, "chuan cmnr", Toast.LENGTH_SHORT).show();
}
else{questionsAsked = totalQuestions;
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
Toast.makeText(PlayGame.this,tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1), Toast.LENGTH_LONG).show();
isGameEnded=true;
EndGame();
}
mySecondsPassed = config.GetTimeToAnswer();
UpdateTimerColors(mySecondsPassed);
if(questionsAsked >= totalQuestions){
isGameEnded=true;
EndGame();
DisplayResults();
} else {
currentQuestionNumber=GenerateQuestionNumber();
PopulateQuestion();
}
}else{
PausedOrEndedGameResponse();
}
}
and this is my database.java
public Quanly_congviec(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String SQL_String = "CREATE TABLE " + ten_table + "("
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ KEY_NOIDUNG_CONGVIEC + " TEXT,"
+ KEY_THOIGIAN_THUCHIEN + " TEXT, "
+ KEY_MUCDO_QUANTRONG + " TEXT" + ")";
db.execSQL(SQL_String);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
db.execSQL("DROP TABLE IF EXISTS " + ten_table);
onCreate(db);
}
public List<Congviec> getAllCongviec() {
List<Congviec> CongviecList = new ArrayList<Congviec>();
String[] ds_dieukien_loc=null;
String selectQuery = "SELECT * FROM " + ten_table;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, ds_dieukien_loc);
if (cursor.moveToFirst()) {
do {
Congviec Congviec = new Congviec();
Congviec.set_id(Integer.parseInt(cursor.getString(0)));
Congviec.setNoidung_congviec(cursor.getString(1));
Congviec.setThoigian_thuchien(cursor.getString(2));
Congviec.setMucdo_quantrong(cursor.getString(3));
CongviecList.add(Congviec);
} while (cursor.moveToNext());
}
db.close();
return CongviecList;
}
public void them_congviec(Congviec congviec) {
SQLiteDatabase db = this.getWritableDatabase();
String nullColumnHack=null;
ContentValues values = new ContentValues();
if (congviec.get_id()!=-1) values.put(KEY_ID,congviec.get_id());
values.put(KEY_NOIDUNG_CONGVIEC, congviec.getNoidung_congviec());
values.put(KEY_THOIGIAN_THUCHIEN, congviec.getThoigian_thuchien());
values.put(KEY_MUCDO_QUANTRONG, congviec.getMucdo_quantrong());
db.insert(ten_table, nullColumnHack, values);
db.close();
}
public void xoatatca_congviec() {
SQLiteDatabase db = this.getWritableDatabase();
String whereClause="";
String[] whereArgs=null;
db.delete(ten_table, whereClause, whereArgs);
db.close();
}
public void xoa_1_congviec(int id){
SQLiteDatabase db= this.getWritableDatabase();
db.execSQL("delete from " + ten_table + " where _id="+id);
db.close();
}
public int sua_1_congviec(Congviec congviec) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NOIDUNG_CONGVIEC, congviec.getNoidung_congviec());
values.put(KEY_THOIGIAN_THUCHIEN, congviec.getThoigian_thuchien());
values.put(KEY_MUCDO_QUANTRONG, congviec.getMucdo_quantrong());
String whereClause=KEY_ID + "=?";
String[] whereArgs={String.valueOf(congviec.get_id())};
return db.update(ten_table, values, whereClause, whereArgs);
}
}
in the database table has three row but i want to insert the question in row 1, the true answer in row 2 and row three is blank.