Delete all item items in a ListView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.