更新Android的ListActivity时列表数据的变化? [英] Update Android ListActivity when list data changes?

查看:527
本文介绍了更新Android的ListActivity时列表数据的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何刷新 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.

这篇关于更新Android的ListActivity时列表数据的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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