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.