Android : clear listview in Listadapter [duplicate]

烂漫一生 提交于 2019-12-01 16:14:17

问题


Possible Duplicate:
how to clear my listview in 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.


回答1:


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.




回答2:


Simply write listView.setAdapter(null)




回答3:


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);



来源:https://stackoverflow.com/questions/10830656/android-clear-listview-in-listadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!