views:

604

answers:

1

I am using listview to display data, inside listview i am using image in every listeitem.

following method is called from wrapper class

public View getView(int position, View convertView,
    ViewGroup parent) { // implementation }

I am following this tutorial http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/view/List4.html

class DownloadImage extends AsyncTask<Void, Void, Drawable>{
        @Override
        protected Drawable doInBackground(Void... params) {
            return Util.getImageFromURL(imageURL); 
        }

        @Override
        protected void onPostExecute( Drawable d ) {
            getImageIcon().setImageDrawable(d);
        }

}
new DownloadImage().execute();

Above code performs lazy image upload for every listItem.

Problem is after loading first image images are getting overlapped on each other.... any idea why this happening ?

+5  A: 

ListView rows get recycled. You are probably updating a row that was recycled, so the image in question is no longer valid.

In my cwac-thumbnail project, I put the URL in the tag of the ImageView and then confirm that the ImageView still has that tag when I go to update the image. That way, if the ImageView now needs a different image, I don't change it to show the wrong image.

CommonsWare
Thanks alot gr8 implementation still i am looking to cache images.
Faisal khan