kocsisur kocsisur - 1 year ago 65
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();
} 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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download