lundi 20 juillet 2015

Android SQLite query all rows and bind it to a listview

Hi I am following the tutorial on this site http://ift.tt/1IdFLFZ to create a database. However, I can't wrap my mind around how to query all rows and bind it to a list view. Here's my code to find a specific entry

 public Entry findEntry(String entryName) {
    String query = "SELECT * FROM " + TABLE_ENTRY + " WHERE " + ENTRY_NAME + " =  \"" + entryName + "\"";

    SQLiteDatabase db = this.getWritableDatabase();

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

    Entry entry = new Entry();

    if(cursor.moveToFirst()) {
        cursor.moveToFirst();
        entry.setId(Integer.parseInt(cursor.getString(0)));
        entry.setEntryName(cursor.getString(1));
        entry.setEntryDesc(cursor.getString(2));
        entry.setEntryTime(cursor.getString(3));
        entry.setEntryDate(cursor.getString(4));
        entry.setEntryLocation(cursor.getString(5));
        entry.setImgUrI(cursor.getString(6));
    } else{
        entry = null;
    }
    db.close();
    return entry;
}

However I want to SELECT * FROM TABLE_ENTRY and return a list of the entry names and load it into a listview, but i have no idea how.

Aucun commentaire:

Enregistrer un commentaire