我使用列表适配器将值设置为listview。这些值是从webservice api加载的。我需要如何在android中使用列表适配器刷新自定义的列表视图。
有两种方法可以做到这一点:
- 创建一个新的适配器,并在每次重新加载数据时使用
setAdapter
将其设置为ListView - 重用适配器(通过
setData
或类似方法),然后调用notifyDataSetChanged
,从而刷新视图
您需要从适配器中使用notifyDataSetChanged(),为了做到这一点,您的适配器需要扩展BaseAdapter,所以每次更改一些数据时,都会调用
instanceOfAdaper.notifyDataSetChanged()
我猜您一定是在使用AsyncTask方法从WebService中获取数据,只需覆盖此方法,然后像这样在onPostExecute中调用notifyDataSetChanged方法。
protected void onPostExecute(String result) {
adapter.notifyDataSetChanged();
}