Position = 0 often occurs in getview.

Source: Internet
Author: User

The getview method is included in the adapter in Android.

Assume that a custom listview or gridview may modify the height of their items in the program running. In this case, the getview will be called back, so the position is 0.

In this case, the object reference in the item is different from the correct position = 0, but it is only a temporary object.

Therefore, you must add a condition to determine whether the position is not a temporary position = 0.

 
  1. If (parent. getchildcount () = position)
  2. {
  3. // The position is normal.
  4. }
  5. Else
  6. {
  7. // Temporary position = 0
  8. }
When using the gridview, many getviews are printed frequently (more items than the actual items). Normally, only one getview is printed, and the corresponding position of the getview is 0. Otherwise, the getview with the position 0 should be printed.

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.