简体   繁体   English

在Listfragment android中使用自定义listview刷新Listadapter

[英]Refresh Listadapter with custom listview in Listfragment android

我使用列表适配器将值设置为listview.values是从webservice api加载的。我需要如何使用android中的列表适配器刷新自定义列表视图。

There are two ways to do that: 有两种方法可以做到这一点:

  1. Create a new adapter and set it to the ListView with setAdapter every time you reload your data. 每次重新加载数据时,创建一个新适配器并将其设置为带有setAdapter的ListView。
  2. Reuse the adapter (via setData or similar methods) and invoking notifyDataSetChanged after that, so the view is refreshed. 重用适配器(通过setData或类似方法)并在此之后调用notifyDataSetChanged ,以便刷新视图。

您需要使用适配器中的notifyDataSetChanged(),以使适配器需要扩展BaseAdapter,因此每次更改某些数据时,请调用,

instanceOfAdaper.notifyDataSetChanged()

I guess you must be using AsyncTask method to fetch data from WebService,Just override this method,and call notifyDataSetChanged method in onPostExecute like this. 我猜您必须使用AsyncTask方法从WebService提取数据,只需重写此方法,然后像这样在onPostExecute中调用notifyDataSetChanged方法。

protected void onPostExecute(String result) {
    adapter.notifyDataSetChanged();             
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM