Android : clear listview in Listadapter [duplicate

2020-04-05 07:52发布

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.

3条回答
兄弟一词,经得起流年.
2楼-- · 2020-04-05 08:07

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

查看更多
SAY GOODBYE
3楼-- · 2020-04-05 08:18

Simply write listView.setAdapter(null)

查看更多
萌系小妹纸
4楼-- · 2020-04-05 08:32

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.

查看更多
登录 后发表回答