开发者

Android listvitem AsyncTask listitem image dereference

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.


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


EDIT: Since @Hunt has pointed out the above link is dead, here's a great one that is in the official Android developer docs:

  • Android Training → Displaying Bitmaps Efficiently → Displaying Bitmaps in Your UI → Load Bitmaps into a GridView Implementation
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜