Android sqlite: how to retrieve specific data from particular column?

try this:

String query = "SELECT * FROM todo WHERE category='" + vg;

Cursor  cursor = database.rawQuery(query,null);

        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;

String query = "SELECT item_name FROM todo WHERE category =" + vg ;
Cursor  cursor = database.rawQuery(query,null);
if (cursor.moveToFirst()) {
         while (cursor.isAfterLast() != true) {
           string itemname =  cursor.getString(cursor.getColumnIndex("item_name")));
          }
}

Here moveToFirst checks if there are items satisfying the criteria and then loops through cursor using while loop. The string itemname can be replaced by list adaper to populate the data. Hope this helps.

Tags:

Sqlite

Android