如何使用ListAdapter时无效的ListView的新数据 [英] How to invalidate ListView for new data when using ListAdapter

查看:225
本文介绍了如何使用ListAdapter时无效的ListView的新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在一个片段使用默认列表视图的显示正在从URL调用的数据。还有一种情况的ListView包含在SwipeRefreshLayout。然而,当我刷新,旧的数据仍然在列表视图,并在列表的顶部是刚加入的新数据。有没有一种方法来废止旧的数据?结果
我已经使用从像这样的SimpleAdapter类创建的ListAdapter的:结果
ListAdapter适配器=新SimpleAdapter(getActivity(),newsItemList,R.layout.list_item,新的String [] {TAG_TITLE,TAG_DATE,TAG_OWNER},新的INT [] {R.id.news_title,R.id .news_date,R.id.news_owner});
                        lvGeneralNews.setAdapter(适配器); 结果
结果我试图让适配器null或使用自带的ListView中无效()方法。该适配器没有一个 notifyDataSetChanged()方法。照片的 newsItemList 是具有从数据的ArrayList该URL。它宣称,像这样:结果
的ArrayList<&HashMap的LT;字符串,字符串>> newsItemList;

I am making use of a default listview in a fragment to show data that is being called from a URL. There is a SwipeRefreshLayout where the ListView is contained. However when I refresh, the old data is still in the listview and the new data is just added at the top of the list. Is there a way to invalidate the old data?
I have made use of a ListAdapter which is created from the SimpleAdapter class like so:
ListAdapter adapter = new SimpleAdapter(getActivity(), newsItemList, R.layout.list_item, new String[]{TAG_TITLE, TAG_DATE, TAG_OWNER}, new int[]{R.id.news_title, R.id.news_date, R.id.news_owner}); lvGeneralNews.setAdapter(adapter);

I have tried to make the adapter null or use the invalidate() method that comes with the listview. The adapter does not have a notifyDataSetChanged() method.
The newsItemList is an ArrayList that has the data from the URL. It is declared like so:
ArrayList<HashMap<String,String>> newsItemList;

推荐答案

重要的是:
你清晰的ArrayList> newsItemList当你得到新的数据?
如果u做
只是重复:

the important is : do you clear ArrayList> newsItemList when you get new data? if u do just repeat:

      ListAdapter adapter = new SimpleAdapter(getActivity(), newsItemList, R.layout.list_item, new String[]{TAG_TITLE, TAG_DATE, TAG_OWNER}, new int[]{R.id.news_title, R.id.news_date, R.id.news_owner});       
 lvGeneralNews.setAdapter(adapter); 

这篇关于如何使用ListAdapter时无效的ListView的新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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