Android SQLite - Cursor & ContentValues

artem picture artem · Oct 28, 2011 · Viewed 21.6k times · Source

Is there any way to GET the ContentValues object from the SQLite? It's very useful, that we can insert ContentValues in DB, and it should be more useful to get the CV from there.

Answer

David-mu picture David-mu · Jan 3, 2012

You can use the method cursorRowToContentValues(Cursor cursor, ContentValues values) of the DatabaseUtils class.

example

Cursor c = db.query(tableName, 
            tableColumn, 
            where, 
            whereArgs,
            groupBy,
            having,
            orderBy);

ArrayList<ContentValues> retVal = new ArrayList<ContentValues>();
ContentValues map;  
if(c.moveToFirst()) {       
   do {
        map = new ContentValues();
        DatabaseUtils.cursorRowToContentValues(c, map);                 
        retVal.add(map);
    } while(c.moveToNext());
}

c.close();