Modify Cursor columns value in android

◇◆丶佛笑我妖孽 提交于 2019-12-07 10:42:14

问题


I have a Cursor returned From a SQLiteDataBase object , i can use getXXX() to get the content of columns from the cursor , in my case i want to modify "update" data in the cursor using setXXX() method , i know there is no setXXX() methods , but there is CursorWindow object that have this feature , but i can't use it


回答1:


You can't change the cursor.

What you can do is update your database and then use the reQuery() method.

// code to update your db
cursor.requery();

EDIT

Further research show that apparently I am incorrect. You CAN do what you want, but it's quite a bit of work (and no, I haven't tried it, I just requery my cursor).

I found this (using a Google search) on a forum:

You can subclass SQLiteDatabase.CursorFactory to return, from its newCursor method, a subclass of SQLiteCursor. This factory gets passed to the SQLiteOpenHelper constructor so, when you query it, it will return Cursors of your new SQLiteCursor subclass type. The SQLiteCursor subclass can then expose methods that manage its protected mWindow field, which is a CursorWindow. This object has putXxx methods to manipulate the data.




回答2:


You cannot alter values returned by Cursor. You either need to update your database, hence changing the values pointed by returned cursor or copy the values you get using getXXX into other variables.



来源:https://stackoverflow.com/questions/10414860/modify-cursor-columns-value-in-android

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