开发者

Android ListView mixes up images while loading over internet

I have an application that contains a couple of listviews. The listviews contains items that consist of imageviews and textviews.

All images are thumbnail sized on a server and the pattern used for loading them is like this:

  • Instanciate a DrawableManager
  • in the getView method i do the following 1 ) Pass the thumb uri and the ImageView instance to the drawablemanagers getImageAsync method 1.2 ) The method will first look on sd card if the image exists if so load it from SD card and save a softreference + update imageview drawable 1.2 ) If not exists on sd. Fetch from HTTP and save on SD (if there is enough space) put as softreference and update imageview drawable.

When the images exists on sd card everything works fine. But first time (or when using the app without sd card) the images seems to be populated into the wrong listviews rows when scrolling. When i stop scroll the problem fix开发者_如何转开发es it self after a couple of seconds.

Its almost like if the ImageView references are pooled or something.

Any ideas?

I also include the getView method:

public View getView(int position, View convertView, ViewGroup parent) {
                    ViewHolder vh;
                    if (convertView == null) {
                        convertView = inflater.inflate(R.layout.informationrow, null);
                        vh = new ViewHolder();
                        vh.imageView = (ImageView) convertView.findViewById(R.id.rowInformationIcon);
                        vh.textView = (TextView) convertView.findViewById(R.id.rowInformationTitleLine);
                        convertView.setTag(vh);
                    }
                    else
                    {
                        vh = (ViewHolder) convertView.getTag();
                    }

                    CustomCategory cc = items.get(position);
                    if (cc != null) {
                        vh.textView.setText(cc.get_name());
                        if (cc.getMediaUrl() != null) {
                            _drawMgr.fetchDrawableOnThread(cc.getMediaUrl(), vh.imageView);
                            vh.imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.imageframe));
                        }
                        else {
                            vh.imageView.setImageDrawable(getResources().getDrawable(R.drawable.trans4040));
                            vh.imageView.setBackgroundDrawable(null);
                        }
                    }

                    return convertView;
            }

Thanks!


I read something that said you always need to set something in each view in a list, even if it's null. So maybe if you add

vh.imageView.setImageDrawable(null);

before

_drawMgr.fetchDrawableOnThread(cc.getMediaUrl(), vh.imageView);

that might fix your problem. Just a guess.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜