Proper implementation of changing ListView data with CursorAdapter

狂风中的少年 提交于 2019-12-22 08:44:53

问题


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?


回答1:


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.




回答2:


If the cursor is back by a ContentProvider and the ContentProvider issues correct notifications, the CursorAdapter will automatically refresh itself i.e. without the need to issue an explicit requery().



来源:https://stackoverflow.com/questions/3639369/proper-implementation-of-changing-listview-data-with-cursoradapter

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