I am developing restaurant menu application. My app has a sqlite table which has these columns:
\"id\", \"category\", \"item_name\"
Content
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.
String query = "SELECT * FROM Table_Name WHERE Col_Name='name'";
Cursor cursor = mDb.rawQuery(query, null);
public List<String> getAllData(String email)
{
db = this.getReadableDatabase();
String[] projection = {email};
List<String> list = new ArrayList<>();
Cursor cursor = db.query(Table_name,null,"email=?",projection,null,null,null,null);
// cursor.moveToFirst();
if(cursor.moveToFirst()) {
do {
list.add(cursor.getString(cursor.getColumnIndex("id")));
list.add(cursor.getString(cursor.getColumnIndex("name")));
list.add(cursor.getString(cursor.getColumnIndex("email")));
list.add(cursor.getString(cursor.getColumnIndex("password")));
// cursor.moveToNext();
} while (cursor.moveToNext());
}
return list;
}