私は2つのテーブル "TABLE_EXAM"と "TABLE_QUESTION"を持っています。次のコード
を使用してレコードをフェッチしますが、レコードは1つしか表示されません。 次をクリックした後に、すべてのレコードを1つずつ表示する必要があります。 button.Pleaseを参考にしてください。
[次へ]ボタンをクリックしてレコードを1つずつフェッチする方法がわかりません。
ありがとうございました。sqliteからレコードを1つずつ取得する方法は?
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;
}
それをどのように行うには?