我有两个表“TABLE_EXAM”和“TABLE_QUESTION”。我使用以下代码获取记录,
但它只显示一条记录。单击下一步按钮后,我需要一一显示所有记录。请 给我一些参考或提示。
我不明白如何通过单击“下一步”按钮逐个获取记录。
提前致谢。
AppearingExamActivity.java
db=new MySQLiteHelper(getBaseContext());
db.getWritableDatabase();
examId=db.getExamId(profile);
final List<ObjectiveWiseQuestion> QuestionWiseProfile= db.getOneQuestion(examId);
for (final ObjectiveWiseQuestion cn : QuestionWiseProfile)
{
db=new MySQLiteHelper(getBaseContext());
db.getWritableDatabase();
//db.close();
txtQuestion.setText(cn.getQuestion());
optionA.setText(cn.getOptionA());
optionB.setText(cn.getOptionB());
optionC.setText(cn.getOptionC());
optionD.setText(cn.getOptionD());
correctOption=cn.getCorrectOption();
}
}
btnNext.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
db=new MySQLiteHelper(getBaseContext());
db.getWritableDatabase();
owq.getCorrectAnswer();
owq.setExamId(examId);
//owq.getExamId();
owq.getQuestionId();
db.addResultDetails(owq);
db.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
MySQLiteHelper.java
public List<ObjectiveWiseQuestion> getOneQuestion(int examId)
{
// long index = 0;
List<ObjectiveWiseQuestion>LocwiseProfileList=new ArrayList<ObjectiveWiseQuestion>();
db = getReadableDatabase();
String selectQuery=("select * from question where exam_id ='"+ examId +"'");
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
{
do {
ObjectiveWiseQuestion owq= new ObjectiveWiseQuestion();
owq.setQuestionId(cursor.getInt(0));
owq.setExamId(cursor.getInt(1));
owq.setQuestion(cursor.getString(2));
owq.setOptionA(cursor.getString(3));
owq.setOptionB(cursor.getString(4));
owq.setOptionC(cursor.getString(5));
owq.setOptionD(cursor.getString(6));
owq.setCorrectOption(cursor.getString(7));
LocwiseProfileList.add(owq);
} while(cursor.moveToNext());
db.close();
}
return LocwiseProfileList;
}
怎么做?