如何刷新一个ListView重新查询其光标重新填充它的数据和观点 [英] How to refresh a ListView to requery its cursor to repopulate its data and its views

查看:126
本文介绍了如何刷新一个ListView重新查询其光标重新填充它的数据和观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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 (你的第二个场景以上)。你可以看到一些 <一href="http://github.com/commonsguy/cw-android/tree/master/ContentProvider/ConstantsPlus/">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.

这篇关于如何刷新一个ListView重新查询其光标重新填充它的数据和观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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