正确的实施与不断变化的CursorAdapter的ListView数据 [英] Proper implementation of changing ListView data with CursorAdapter
问题描述
我通过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 yourCursorAdapter
, which will trigger an automatic update of theListView
, 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 freshCursor
, then usechangeCursor()
orswapCursor()
on yourCursorAdapter
.这篇关于正确的实施与不断变化的CursorAdapter的ListView数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!