First, don't append. You need the ImageView
there anyway. Have the ImageView
use a placeholder image, that you replace with the final image when it is ready.
Second, consider using an existing library that knows about Adapter
recycling, such as Picasso. Admittedly, I don't know if Picasso has support for ExpandableListAdapter
, as I rarely use ExpandableListView
.
If you determine that there is no suitable library, you'll need some logic in your getChildView()
and/or getGroupView()
methods that can deal with recycling and your background work. One fairly simple approach is to tuck the URL of the image needed by the ImageView
in the tag of the ImageView
via setTag()
. Your onPostExecute()
can then compare the URL it just downloaded with the URL from the ImageView
tag, and if they do not match, do not update the ImageView
. This means that you will download some images unnecessarily, so a more sophisticated approach will arrange to cancel the AsyncTask
that is downloading the image. And I am sure that there are other approaches as well.