修改Android的游标列值 [英] Modify Cursor columns value in android

查看:116
本文介绍了修改Android的游标列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游标返回从SQLiteDataBase对象,我可以使用的getXXX()从游标获取列的内容,在我的情况我想用修改更新数据光标的setXXX()的方法,我知道有没有的setXXX()方法,但有这个功能CursorWindow对象,但我不能使用它

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

推荐答案

您不能更改光标。

你可以做的就是更新您的数据库,然后使用 REQUERY()方法。

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

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

修改

进一步的研究表明,显然我是不正确。你可以做你想做的,但它是相当多的工作的(不,我还没有尝试过,我只是重新查询我的光标)。

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:

您可以继承SQLiteDatabase.CursorFactory返回,从
  newCursor方法,SQLiteCursor的子类。这家工厂被传递
  到SQLiteOpenHelper构造函数,因此,当您查询,它会
  返回新SQLiteCursor子类型的光标。该
  然后SQLiteCursor子类可以公开管理方法,其
  保护mWindow场,这是一个CursorWindow。这个对象有
  putXxx方法来操作数据。

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.

这篇关于修改Android的游标列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆