开发者

android - ListAdapter deleting item - refreshing view

开发者 https://www.devze.com 2023-02-19 18:48 出处:网络
I\'m trying to delete items 开发者_Python百科from a ListView using a custom adapter which extends SimpleCursorAdapter.

I'm trying to delete items 开发者_Python百科from a ListView using a custom adapter which extends SimpleCursorAdapter.

When I try to delete one of the list items, I want to the ListView to refresh itself. I have read from other posts, that you can do this by calling Cursor.requery().

While the database is consistent, that is, the deletion takes place, Cursor.requery() returns true, but instead of showing me the updated list, it shows me an empty list with the empty TextView I have set in my xml file with this id android:id="@id/android:empty"

Any ideas?

Thanks


You have other code in there beyond the requery() call that is messing things up. Here is a sample project demonstrating the use of requery() to update a ListView when a new item is inserted or deleted.


Ok I've found my own problem.

I was closing the database.

Perhaps I only need to close the database when the activity is paused/stopped etc..

0

精彩评论

暂无评论...
验证码 换一张
取 消