java Android - 你能更新 SQLite 结果的游标吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7973607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android - Can you update a Cursor for SQLite results?
提问by Jake Wilson
One of my methods returns a Cursor from some SQLite query results.
我的一种方法从一些 SQLite 查询结果返回一个 Cursor。
As I'm navigating through the cursor, there are some records I want to change/update. Can I update directly with the cursor? Or do I have to manually UPDATE
using the record ID from the cursor?
当我浏览光标时,我想更改/更新一些记录。可以直接用光标更新吗?还是我必须手动UPDATE
使用游标中的记录 ID?
采纳答案by Lycha
You can not directly update records with the cursor. Read the Android Cursor doc.
不能直接用游标更新记录。阅读Android Cursor 文档。
回答by SpeedBirdNine
You need to implement a Content Provider that allows to update the record, in short you need to override the update function in your ContentProvider class.
您需要实现一个允许更新记录的内容提供者,简而言之,您需要覆盖您的 ContentProvider 类中的更新功能。
public int update(Uri uri, ContentValues values, String where, String[] whereArgs)
In short you'll have to update them, this is not done directly from the data received in the Cursor.
简而言之,您必须更新它们,这不是直接从 Cursor 中接收到的数据完成的。
回答by Mathieu Hausherr
To do that the best way is to implement a content provider for your data http://developer.android.com/guide/topics/providers/content-providers.html
要做到这一点,最好的方法是为您的数据实现一个内容提供者http://developer.android.com/guide/topics/providers/content-providers.html
You can use framework like datadroid for that http://datadroid.foxykeep.com/
你可以使用像 datadroid 这样的框架http://datadroid.foxykeep.com/