Skip to content Skip to sidebar Skip to footer

Imageview Overlap When Adding More Items In Existing Listview

I am creating a ListView which as a TextView and ImageView as a list item row. initially i am loading default items from local database in a listview view and I have a update butto

Solution 1:

I suspect that your imageDownloader is calling setImageResource (or equivalent--it's setting the src attribute) of your ImageView, while you are initially calling setBackgroundResource. That would explain the overlap.

What you need to do is change setBackgroundResource to setImageResource in the following code:

if(data.getTemplateIconId()!=0 && data.getTemplateIconUrl()==null ){

                Log.d("Load icon ","Default Load");

                // This line should say setImageResource:
                holder.templateIcon.setBackgroundResource(data.getTemplateIconId());
 } else ... 

The issue that @Akos mentions (which he appears to have deleted) will be an issue for you if a download takes a long time and the view has already been reused. To restate what he stated, once you get this working via the solution above, you will find that if an image download takes a long time (so long that the row has already been reused, and the new image set) that your images may be overwritten with older images.

Therefore, inside of imageDownloader you will also want to say, before downloading:

imageView.setTag(url);

and then after the download completes, before setting the image in the ImageView:

if(!(String)imageView.getTag().equals(url)
{ 
     return; 
}

This way, if the ImageView has been reused by another row in the meantime, the download will simply abort.

Post a Comment for "Imageview Overlap When Adding More Items In Existing Listview"