我有一种方法可以从数据库答案表中获取答案 ID(特定于每个答案)-getAnswerId()
但我想改变它。我在问题数据库中创建了 answer0,answer1, answer2 列,并希望将 0,1,2 作为 answerId 。如何为 getAnswerId() 识别它?
不久;
列名:answer0,answer1,answer2
取“0,1,2”作为“ answerId ”并放入“ getAnswerId() ”
然后我想像这样使用它:
公共 int getAnswerId() {
return this.answerId; }
编辑:
sqlhelper:
final String query = "SELECT " +
"answer._id, answerlang.AnswerText, answer.Correct, " +
"answersquestions.QuestionID" +
" FROM answersquestions" +
" INNER JOIN answerlang" +
" ON answersquestions.AnswerID = answerlang.AnswerID" +
" INNER JOIN answer" +
" ON answerlang.AnswerID = answer._id" +
" WHERE answersquestions.QuestionID IN ( " +
allQuestionIds +
" ) ORDER BY answersquestions.QuestionID ";
this.cursor = this.db.rawQuery(query, null);
if (this.cursor.moveToFirst()) {
do {
for (final Question q : questions) {
if (q.getQuestionId() == this.cursor.getInt(3)) {
q.addAnswer(new Answer(this.cursor.getInt(0),
this.cursor.getString(1),
(this.cursor.getInt(2) == 1 ? true : false)));
}
}
} while (this.cursor.moveToNext());
}
this.cursor.close();
this.cursor.getInt(0) 接受 answer._id (_ids from answer table)
我更改了数据库结构并将 answer0、answer 1、answer 2 添加到 answerlang 表中。所以我需要一张表中每个答案的 id 。我想取QuestionID和 0(或 1,2)(来自 answer0,1,2)所以answerID = QuestionID+0对每个答案都是特别的
问题是如何间隔QuestionID+0去放置,而不是this.cursor.getString(0)
// // // // \ \ \ \
我的问题总结:
use **this.sample.getInt()** instead of this.cursor.getInt(0)
for example:
this.sample.getInt() : will have interval 10,11,12 for question 1 (QuestionID=1, answer0=0 so answer0 id = 10, answer1 id = 11, answer2 id = 12 as spesific id )
will have interval 20,21,22 for question 2 (QuestionID=2, answer0=0 so answer0 id = 20 ...... as spesific id )