In the article Multithreading For Performance from Android Developer Blog, convertView
is used in Adapter.getItem()
to display a list of ImageView
, which are downloaded through HttpRequest.Yet, I also see some Android tutorials that don't use the convertView
, and just inflate a new view in Adapter.getItem()
.
I'm wondering what's the advantage of using convertView
? How does it recycle the used view? Where are the used view cached?
I ask this question because I didn't use convertView
in my project and I want to know the cost for not using it. Below is my implementation of a listView of images.
Instead of using convertView
, I inflate a new view in Adapter.getItem()
. Besides, I create a wrapper class to hold the staff in each item of listView
. Once the image is downloaded, it will be stored as bitmap in the wrapper class for each list item(The image is small). In this way, I can avoid the duplicate downloading of the same image. And this also avoid the race condition issues talked in Multithreading For Performance. But I'm still a little worried, is there any issues that not good by using my method?
FYI: the article recommended by @Carl Anderson gives details about how convertView works in adapter. The Google IO by Romain Guy that is suggested in this article is another good reference.
In a word, using convertView is both space and time optimized. Besides, I've abandoned my own imageDownloader and use the Picasso that is recommended by @CommonsWare. It works like a charm.