正确的实施与不断变化的CursorAdapter的ListView数据 [英] Proper implementation of changing ListView data with CursorAdapter

查看:175
本文介绍了正确的实施与不断变化的CursorAdapter的ListView数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过CursorAdapter的填充一个ListView。我给我的用户改变在列表中的数据的能力。例如,用户可以标记的行为是未读(的数据是消息)。

假设我的用户打上一排未读。将适当的实施标志着数据库的行为已读,然后重新查询光标?


解决方案

  

请问一个正确实施标志着数据库的行为已读,然后重新查询光标?


是的,这是正确的答案。在重新查询()将触发的自动更新你的的CursorAdapter ,这将触发<$ C的自动更新$ C>的ListView ,这将触发来自用户的自动笑容。 : - )

更新

重新查询()方法是pcated德$ P $。更好的方法时下正在运行一个查询,以取得一个新的光标,然后用 changeCursor() swapCursor()的CursorAdapter

I have a ListView populated via a CursorAdapter. I give my user the ability to alter the data in the list. For example, the user can mark a row as being unread (the data are messages).

Suppose my user marked a row unread. Would a proper implementation mark the row in the database as read and then requery the Cursor?

解决方案

Would a proper implementation mark the row in the database as read and then requery the Cursor?

Yes, that's the right answer. The requery() will trigger an automatic update of your CursorAdapter, which will trigger an automatic update of the ListView, which will trigger an automatic smile from the user. :-)

UPDATE

The requery() method is deprecated. A better approach nowadays is to run a query to get a fresh Cursor, then use changeCursor() or swapCursor() on your CursorAdapter.

这篇关于正确的实施与不断变化的CursorAdapter的ListView数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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