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