可能是重复问题:
如何在Android中清除我的ListView?
在Android中,我使用了一个ListAdapter、SimpleAdapter并传递了一个数组,我想要清除ListView的内容。但是它不是清除,而是将记录追加到我的ListView中。
可能是重复问题:
如何在Android中清除我的ListView?
在Android中,我使用了一个ListAdapter、SimpleAdapter并传递了一个数组,我想要清除ListView的内容。但是它不是清除,而是将记录追加到我的ListView中。
只需编写listView.setAdapter(null)
您可以从这里获取我的自定义适配器。 TestAdapter
现在添加一个像这样的方法...
public void clearAdapter()
{
deviceNames.clear();
selected.clear();
notifyDataSetChanged();
}
现在从您的 Activity 中调用 youListAdapter.clearAdapter()
。
使用notifydataSetInValidated()
在适配器上通知您的列表视图数据集不再有效。或将适配器设置为null:l.setAdapter(null);