SQLite
 sql >> Datenbank >  >> RDS >> SQLite

SQLite-Abfrage:Alle Spalten einer Zeile abrufen (Android)?

So sollte es sein

Cursor cursor = db.rawQuery(selectQuery, null);
    ArrayList<HashMap<String, String>> maplist = new ArrayList<HashMap<String, String>>();
    // looping through all rows and adding to list

    if (cursor.moveToFirst()) {
        do {
            HashMap<String, String> map = new HashMap<String, String>();
            for(int i=0; i<cursor.getColumnCount();i++)
            {
                map.put(cursor.getColumnName(i), cursor.getString(i));
            }

            maplist.add(map);
        } while (cursor.moveToNext());
    }
    db.close();
    // return contact list
    return maplist;

Bearbeiten Benutzer wollte wissen, wie man ListView mit HashMap füllt

//listplaceholder is your layout
//"StoreName" is your column name for DB
//"item_title" is your elements from XML

ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.listplaceholder, new String[] { "StoreName",
                "City" }, new int[] { R.id.item_title, R.id.item_subtitle });