Today the project encounters a one-click Removal requirement for all list items in the ListView, which is recorded here.
The first idea is to set an empty adapter, so that after the empty adapter assigned to the ListView, but later think it is too troublesome, went to look for the official time to give such a method.
Don't say, there really is a similar way!
ViewGroup class below There is a removeallviews () method, look at the name is like, tried a bit unexpectedly not!
Reported such a mistake:
isnotin AdapterView
Actually said this is not for the Adapterview to use, racist ah, there are wood!
With such a bufen mentality, I tried to find a way to use, sure enough, I found her-also is the ViewGroup class method, the name is very similar to--removeallviewsinlayout ().
As the saying goes, dragon are different, although the two methods are pro-siblings, but the latter is very kind, adapterview can play with it happily.
After the use of a test, found that although no error, but all the item is also well lying in the ListView, a click on the item will disappear all.
In fact, this is because the view does not refresh the problem, Removeallviewsinlayout () and then call Postinvalidate () to refresh the next.
mList.removeAllViewsInLayout(); mList.postInvalidate();
That way, it's OK.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Delete all item items in a ListView