ListView Cache mechanism step-by-step

Source: Internet
Author: User

When using ListView and GrildView, the cache mechanism is often used for random searches. There are thousands of examples, but the explanations are very consistent. Few people have explained the pitfalls they step on.

Test requirement: GrildView is displayed in three columns. The default background is white. If the current ID can be divisible by two, an image is displayed. If the current ID can be divisible by three, and the background cannot be divisible by two, it turns gray.

GetView code:

Running Display: The first image is displayed normally before it slides. Then, the second image is displayed as needed. The problem is that the image order is disordered, but why is the name incorrect, well, it's all about cache.

Looking back and analyzing the code in getView, we know that the cache will record the View status on the current interface. So, sliding back, the reason why the text is not disordered is that every time it is re-assigned, however, our view is indeed conditional judgment, that is to say, if the value is not re-assigned, it will be judged in the cache status of the previous interface, this causes the image disorder on the gray background. The solution is to comment out the code in lines 10-and cancel the comment. The view is assigned a value each time a screen is displayed, there will be no disordered order.

 

ListView Cache mechanism step-by-step

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.