更新Android的ListActivity时列表数据的变化?数据、列表、Android、ListActivity

2023-09-05 00:19:43 作者:四野无人

我想知道如何刷新 ListActivity 当我改变/添加数据。

I wanted to know how to refresh a ListActivity when I change/add data to it.

我首先想到的是 ListAdapter 会知道什么时候该名单的变化,但是当我添加元素到列表中没有任何关于更新 ListActivity ,只有当我关闭ListActivity并再次打开它,我看到发生的变化。

I first thought that ListAdapter would know when the list is changes, but when I have added elements to the list there is no update on the ListActivity, only when I close the ListActivity and reopen it again I see the changes occur.

所以,我搜索了所有的方法,如: update()方法,refesh()之类的东西,却是没有。 看来我还没有得到这个概念,有人可以帮我吗?

So I searched for any method such as: update(), refesh() or something like that, but there is none. It seems I haven't gotten the concept, can someone help me please?

推荐答案

如果您使用的是 ArrayAdapter ,通过适配器操作列表中的内容 - 不触摸基础列表。有添加()插入()删除()方法对 ArrayAdapter

If you are using an ArrayAdapter, manipulate the contents of the list through the adapter -- do not touch the underlying list. There are add(), insert(), and remove() methods on ArrayAdapter.

如果您使用的是的CursorAdapter ,运行重新查询()光标

If you are using a CursorAdapter, run a requery() on the Cursor.

 
精彩推荐
图片推荐