An odd question about the ListView in Android

Source: Internet
Author: User
<span id="Label3"><p>today, when doing the project, I found a strange question about the listview, that is, the Android:height property of the ListView affects the number of calls to the GetView () method of the ListView in the Program. If you set the Android:height property of the ListView to 0dp, set android:weight=1 at the same time, or directly set the Android:height property to "wrap_content", So when the ListView displays the data, the number of times the GetView () is executed will not be the size of the incoming data collection, but will be larger or even larger than the value of size, but if the Android:height property of the ListView is set to Match_ parent, the number of GetView () is executed exactly as the size of the incoming data collection.</p><p>So what's the effect of this on the program, and the impact of my project-if the Listview's Android:height property is not "match_parent"? Then when a checkbox in the ListView item needs to be automatically selected according to the data, it will cause confusion, and each time you re-enter this interface, the checkbox in the ListView is not the same, I just found this effect, But I guess there are some other effects.</p><p>The interpretation of this phenomenon is probably explained by the online access to the relevant information:</p><p>We generally set the Android:height property of the ListView to Match_parent so that the actual height of the ListView can be measured directly in the program, but if we set the Height property to wrap_content, or 0DP (set weight to 1 at the same time) will cause the actual height of the ListView to be impossible to measure, and some calculations will be needed to determine the actual height of the listview, while the rendering of the ListView is triggered during the calculation, GetView () will be called multiple times, causing GetView () to be called several times the size of the incoming data collection.</p><p>therefore, in the actual project, it is best to set the ListView height attribute to match_parent, which can optimize the efficiency of the Program.</p><p>An odd question about the ListView in Android</p></span>

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.