When we use the ListView to load images asynchronously, in the case of fast sliding or bad network, the picture will appear dislocation, repetition, flashing and other problems, in fact, these problems summed up is a problem, we need to be optimized for the listview of these problems.
For example, there are 100 item on the ListView, one screen only shows 10 item, we know that GetView () Convertview is used to reuse the view object, because one Item corresponds to a View object, The ImageView control is the view object obtained through Findviewbyid (), and when we reuse the View object, the ImageView object is also reused. For example, the 11th item View re-uses the 1th Item view object, then the ImageView is reused at the same time, so when the picture is not downloaded, The data shown in this ImageView (11th item) is the data for reuse (1th item).
1:item Picture Display Repeat
This display repetition means that the current line item shows a picture of the previous line item.
For example, the ListView slides to the 2nd row to load a picture asynchronously, but the load is slow, the ListView has slid to line 14th during the loading process, and the picture is loaded at the end of the slide. Line 2nd is no longer in the screen, according to the caching principle described above, the 2nd row of the View object may be reused in line 14th, so we see that the 14th line shows the image that should belong to the 2nd line, causing the display to repeat.
2. Item image shows confusion
This display disorder refers to a line item that shows a picture that does not belong to the line item.
The same reason as above.
3. Item image Display flashes
The other situation described above, if the 14th line of pictures and quickly loaded the end, so we see the 14th line first shows the re-use of the 2nd line of the picture, and immediately display their own images to cover the flicker confusion.
Solution:
through the above analysis we know that the cause of the disorder is the asynchronous loading and the object is reused, if each time GetView can give an identity to the object, when the asynchronous loading is done to compare the identity with the current row of the identity of the item is consistent, the same is displayed, otherwise do not do processing.
principle : First give ImageView set a tag, this tag is set in the URL of the image, and then in the loading time to get this URL and to load that position in the URL comparison, if not the same load, the same is the same as the former will not load.
Android ListView Asynchronously loading picture dislocation, repetition, flicker analysis and solutions