kocsisur kocsisur - 21 days ago 6
Java Question

How to get the items of a Database by ID?

I'm developing a quiz-like application and I can't seem to get the questions by "Category" (the category is an ID, because it will be assigned to different locations)

I have this method:

public List<Question> getAllKerdesByHelyID(int ID){
{
List<Question> questionlist = new ArrayList<Question>();

String selectQuery= " SELECT * FROM " + TABLE_QUEST + "WHERE " + KEY_HELYID + " = " + ID;

dbase = this.getReadableDatabase();
Cursor cursor = dbase.rawQuery(selectQuery, null);

if (cursor.moveToFirst()) {
do {
Question quest = new Question();
quest.setID(cursor.getInt(0));
quest.setQUESTION(cursor.getString(1));
quest.setANSWER(cursor.getString(2));
quest.setOPTA(cursor.getString(3));
quest.setOPTB(cursor.getString(4));
quest.setOPTC(cursor.getString(5));
quest.setID(cursor.getInt(6));
questionlist.add(quest);
} while (cursor.moveToNext());
}
// return quest list
return questionlist;

}
}


For now i'm just creating the application so not all feautre is implemented.
KEY_HELYID should be the integer i'm trying to filter.

quesList=db.getAllKerdesByHelyID(5); is how i'm calling this method on the activity.

Thank you for your help!

Answer

I found out the problem, the table was empty because of a typo in the creation of the database table