Update Android ListActivity when list data changes?

一个人想着一个人 提交于 2019-12-03 09:02:48

问题


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

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.

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?


回答1:


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.

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




回答2:


Try ArrayAdapter:notifyDataSetChanged
Google docs link




回答3:


Maybe you should do this setListAdapter(listAdapter);



来源:https://stackoverflow.com/questions/1538796/update-android-listactivity-when-list-data-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!