Android SQLite - 光标和内容值

标签 android sqlite android-cursor

有没有办法从 SQLite 获取 ContentValues 对象?

非常有用,我们可以在 DB 中插入 ContentValues,从那里获取 CV 应该更有用。

最佳答案

您可以使用cursorRowToContentValues(Cursor cursor, ContentValues values)的方法的DatabaseUtils类。

例子

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();  

关于Android SQLite - 光标和内容值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7932420/

相关文章:

Android Recyclerview Onclicklistener 不适用于 Cursor

Android RecyclerView + CursorLoader + ContentProvider + "Load More"

java - 在 Cordova 中传递 ActivityResult

java - 有没有办法在我自己的应用程序中使用 Android 上的 native 消息应用程序?

java - map : check wether a point is on polyline or not

sqlite - SQlite删除内部联接

java - 如何清除散列映射<string,string> 值?

android - 如何从 Environment.DIRECTORY_PICTURE 目录中获取所有图像并显示在我的自定义图库中

java - 如何检查一个方法是否被子进程调用?

java - Java SQLexecuteQuery 抛出有效 sql 语句错误