如何清除Android ListView并用新数据填充它? [英] How to clear an Android ListView and populate it with new data?

查看:88
本文介绍了如何清除Android ListView并用新数据填充它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一活动中有一个微调框和一个列表视图.listview加载有项目列表.我希望当用户单击微调器中的项目时,列表视图将被清除,并且将根据微调器中的项目选择来加载新的列表视图

I have a spinner and a listview in the same Activity. The listview is loaded with a list of items. i want when user clicks on the item from spinner the listview will be clear and new listview will load according to item chooses in spinner

    setListAdapter(new ArrayAdapter<String>(this, R.layout.listviewxml, video));

       ListView lv=getListView();

       lv.setTextFilterEnabled(true);

请告诉我该怎么做?

我无法清除列表视图

推荐答案

如果您已将列表或数组传递给适配器,则

// Clear collection..
collection.clear();
// Add data to collection..
collection.add();
// Refresh your listview..
listview.getAdapter().notifyDataSetChanged();

(这些代码类似于伪代码,您的语法可能会有所不同)

(These codes are like pseudo code, your syntax may vary)

这篇关于如何清除Android ListView并用新数据填充它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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