我已經使用光標在sqlite數據庫獲取記錄。Android的Sqlite Cursur沒有返回正確的值
我的代碼如下:
btnnext.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
displayQuestion();
});
}
private void displayQuestion() {
db.openDataBase();
SQLiteDatabase sqlitedatabase = db.getWritableDatabase();
Cursor cur;
cur = sqlitedatabase.rawQuery("select quiz_id, opt_ans from options" ,null);
cur.moveToFirst();
db.close();
radioGroup.removeAllViews();
for (int i = 0; i <= 3; i++) {
l++;
Log.v("value of l",l+"");
radioButton = new RadioButton(this);
String str_opt = cur.getString(cur.getColumnIndex(Database_helper_class.OPT_ID));
radioButton.setText(str_opt);
Log.v("value of l",l+""+str_opt);
radioButton.setId(i);
cur.moveToPosition(l);
radioGroup.addView(radioButton);
}
}
和我得到的日誌是:
03-07 18:32:03.190: V/value of l(28903): 1video
03-07 18:32:03.200: V/value of l(28903): 2
03-07 18:32:03.210: V/value of l(28903): 2sound
03-07 18:32:03.210: V/value of l(28903): 3
03-07 18:32:03.221: V/value of l(28903): 3image
03-07 18:32:03.231: V/value of l(28903): 4
03-07 18:32:03.240: V/value of l(28903): 4word document
03-07 18:32:05.561: V/value of l(28903): 5
03-07 18:32:05.571: V/value of l(28903): 5video
03-07 18:32:05.580: V/value of l(28903): 6
03-07 18:32:05.590: V/value of l(28903): 6A process
03-07 18:32:05.590: V/value of l(28903): 7
03-07 18:32:05.601: V/value of l(28903): 7A system software
03-07 18:32:05.601: V/value of l(28903): 8
03-07 18:32:05.610: V/value of l(28903): 8A document
和我使用的數據庫是
opt_ans,"opt_id","quiz_id"
video,"1","1"
sound,"2","2"
image,"3","3"
word document,"4","4"
appliction,"5","5"
A process,"6","6"
A system software,"7","7"
A document,"8","8"
hgfhgfh,"9","9"
hgfhgf,"10","10"
tytrytr,"11","11"
ytrytrytr,"12","12"
tytrytrytr,"13","13"
tytrytryt,"14","14"
tytyt,"15","15"
ytytyt,"16","16"
ytytryt,"17","17"
tytytr,"18","18"
tytytryt,"19","19"
htghyt,"20","20"
現在我的問題:
爲什麼我會得到v意識到5日和9日的指數也在這些指數有不同的價值?
將是巨大的,如果你可以清理註冊你的代碼。刪除所有註釋行,因爲它們對我們來說不是很有趣。這將使我們更容易以這種方式閱讀您的代碼。 – WarrenFaith 2012-03-07 13:20:04