Android:清除Listadapter中的列表视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10830656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android : clear listview in Listadapter
提问by AnnaSmith
Possible Duplicate:
how to clear my listview in android
可能的重复:
如何在 android 中清除我的列表视图
In android, i have used a listadapter, simple adapter and passed an array and i want to clear the listview contents? Instead of clearing , it is appending the records to my listview.
在android中,我使用了一个listadapter、简单的适配器并传递了一个数组,我想清除listview的内容?它不是清除,而是将记录附加到我的列表视图中。
回答by Shaiful
Grab my Custom adapter from here. TestAdapter
从这里获取我的自定义适配器。测试适配器
Now add a method like this..
现在添加一个这样的方法..
public void clearAdapter()
{
deviceNames.clear();
selected.clear();
notifyDataSetChanged();
}
Now call youListAdapter.clearAdapter()
from you Activity.
现在youListAdapter.clearAdapter()
从你的活动中调用。
回答by user755278
Simply write listView.setAdapter(null)
只需编写 listView.setAdapter(null)
回答by Akhil
Use notifydataSetInValidated()
on your adapter to notify your listview that the data set is not longer valid. or set your addapter to null : l.setAdapter(null);
notifydataSetInValidated()
在您的适配器上使用以通知您的列表视图数据集不再有效。或将您的适配器设置为 null :l.setAdapter(null);