开发者

Android listvitem AsyncTask images overlapping

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) { // implementa开发者_运维知识库tion }

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 ?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜