views:

330

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<ImageView, Void, Drawable>{
        private ImageView iv;

        @Override
        protected Drawable doInBackground(ImageView... params) {
            iv = params[0];
            return Util.getImageFromURL(imageURL); 
        }

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

}
new DownloadImage().execute(getImageIcon());

getImageIcon contains the reference of the inflater layout's imageview.

Now problem is first when 2nd listeitem image gets loaded it also resplaces the first listeitem image and so on...

i think it is listitem's referencing issue but above code should work b/c i am passing imageview reference inside.

+1  A: 

This blog post may provide some guidance on using images with ListViews.

Roman Nurik