private void populateQuestionList() {
int QuestionTableSubjectId = questionModelObject.getSubjectId();
ArrayList<QuestionModel> questionArrayList = QuestionManager.getQuestionManager(this).getQuestionBySubjectID(QuestionTableSubjectId);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < questionArrayList.size(); i++) {
TableRow row = (TableRow) inflater.inflate(R.layout.item_ctrl_list_row, null);
row.setOnClickListener(this);
TextView questionTV = (TextView) row.findViewById(R.id.tv_ctrl_name);
String question = questionArrayList.get(i).getQuestion();
questionTV.setText(question);
row.setTag(questionArrayList.get(i));
questionList.addView(row);
}
}
此方法用于从数据库和代码
列表调用方法getQuestionBySubjectID
中显示问题
public ArrayList<QuestionModel> getQuestionBySubjectID(int subjectId) {
ArrayList<QuestionModel> questionArrayList = new ArrayList();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("select * from Questions where subject_id=" + subjectId, null);
res.moveToFirst();
while (res.isAfterLast() == false) {
QuestionModel questionModelObject = new QuestionModel();
questionModelObject.setQuestionId(res.getInt(res.getColumnIndex("questionId")));
questionModelObject.setQuestion(res.getString(res.getColumnIndex("question")));
questionModelObject.setQuestion(res.getString(res.getColumnIndex("answerOne")));
questionModelObject.setQuestion(res.getString(res.getColumnIndex("answerTwo")));
questionModelObject.setQuestion(res.getString(res.getColumnIndex("answerThree")));
questionModelObject.setQuestion(res.getString(res.getColumnIndex("answerFour")));
questionModelObject.setAnswerOne(res.getString(res.getColumnIndex("correctAnswer")));
questionArrayList.add(questionModelObject);
res.moveToNext();
}
return questionArrayList;
}
这段代码有什么问题?我不知道错误是什么(在Cursor中)。
答案 0 :(得分:0)
问题是您的光标不包含任何结果。可能是由错误的查询引起的。