如何刷新一个ListView重新查询其光标重新填充它的数据和观点它的、光标、观点、数据

2023-09-06 14:44:08 作者:暖暖的情话

我有一个ListView它使用CursorAdatper作为它的适配器。 我想有列表视图

I have a ListView which uses a CursorAdatper as its adapter. I would like to have the list view to

重新查询它的数据 在更新其观点,一旦重新查询完成。

我想:

CursorAdapter adapter = (CursorAdapter)listView.getAdapter();
adapter.notifyDataSetChanged();

和我尝试:

CursorAdapter adapter = (CursorAdapter)listView.getAdapter();
adapter.getCursor().requery();

但没有奏效。我已将我的的ContentProvider 的查询方法一个破发点,但我没有看到重新查询被称为或我的ListView得到刷新着新的数据。

but none worked. I have set a break point in my ContentProvider's query method, but I don't see the requery being called or my ListView getting refreshed with new data.

你能告诉我什么是解决我的问题?

Can you please tell me what is the solution to my problem?

感谢你。

推荐答案

调用重新查询()上的数据库或内容提供商光标通过的CursorAdapter 自动刷新名单附于的ListView (你的第二个场景以上)。你可以看到一些 examples这个的。如果不为你工作,可能会有一些bug你的的ContentProvider 或适配器。

Calling requery() on a database or content provider Cursor attached to ListView via a CursorAdapter automatically refreshes the list (your second scenario above). You can see some examples of this. If that is not working for you, there may be some bug in your ContentProvider or adapter.