Android - Can you update a Cursor for SQLite results?

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

One of my methods returns a Cursor from some SQLite query results.

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?

回答1:

You can not directly update records with the cursor. Read the Android Cursor doc.



回答2:

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.

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.

This and this link should help.



回答3:

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

You can use framework like datadroid for that http://datadroid.foxykeep.com/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!