我有一個需要從數據庫答案表 - getAnswerId()一個數組(或其他方式)獲取數據
回答的ID(具體每個答案),但我想改變它的方法。我在問題數據庫中創建了answer0,answer1,answer2列,並且想要將0,1,2作爲answerId。我怎樣才能識別它的getAnswerId()?
不久;列
名稱:answer0,ANSWER1,ANSWER2
以 「0,1,2」 爲 「answerId」,並把它放在 「getAnswerId()」
然後我想使用它像:
公衆詮釋getAnswerId(){
return this.answerId; }
EDITED:
提供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)
我改變數據庫結構並添加了答案0,答案1,答案2答案朗表。 所以我需要一個表中的每個答案的id。 我認爲採取QuestionID和(或1,2-)(來自answer0,1,2) 所以answerID = QuestionID + 0將spesific每個答案
問題是如何間隔QuestionID + 0去的地方,而不是this.cursor.getString(0)
// // // // \ \ \ \
的Sumamry我的問題:
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)
我可以建議你更好地構建問題嗎?我不太確定你在問什麼。 – BlackBox 2013-03-18 10:47:19
你想獲取列的值? – Sajmon 2013-03-18 10:50:03
請清楚提問,以便我們可以幫到您。 – Abx 2013-03-18 10:50:27