问题
This is not a big issue, but it looks strange. In a list or gridview I load images with a delay (e.g. loaded from remote place). I'm recycling the items, using convertView. When I scroll down fast, I see the old images repeated, until the correct images are fetched and replace them.
Is there a way to change this? I tried, for example, at the very start of getView()
(after initializing convertView, if necessary), to set the imageView visibility to GONE
. And set to VISIBLE
after the image has been fetched. But for some reason, this doesn't work (still looks the same).
Thanks!
Edit: I'm not even sure if this is normal behaviour when using recycled views, or if I'm doing something wrong. It doesn't look like a bug when the internet connection is fast, or when fetching from the file system. Then the new images are loaded very fast and the user doesn't see repeated items. But on a slow internet connection, it looks like a bug.
回答1:
Before setting image in row just check if the image belong to the content of view.
I had the same problem sometime back and I had to change my image downloader so that it takes image url as well as meta data so that once download is complete, i can compare meta-data with view's data.
来源:https://stackoverflow.com/questions/11961278/old-items-visible-a-while-in-listview-or-gridview-when-recycling