A problem using ListView
Hi geeks!
Here is a problem using ListView.When generating a single list item view, in the method of BaseAdapter.getView, some cont开发者_如何学编程inuous async remote data request may be issued, like getting the photo of a person.
But when the response is back, the list item view might be reused, as the mechanism of ListView works. I cannot find the right view to put the response to.
How did you guys fix this problem?
As you say, there is a good chance that by the time you've loaded the image that the list item is no longer visible or even existing. So you can check what is on screen using ListView.getFirstVisiblePosition() and ListView.getLastVisiblePosition(), if it is onScreen get the item and set the image. Otherwise you have to cache the image (either memory or sd-card depending on how many images and the size of them) and next time getView() is called for that item just use the cached image.
I hope that helps.
I believe what your after is "lazy image loading" + caching. I got my implementation going via this answer. The package is called LazyList.
I hope this helps
精彩评论