0

I used SimpleDraweeView in ListView Item. If the header url is not null, it will display the image from the network, or it will display the default image from local drawable.

The code is as follow:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.info_contact_item,null);
            holder.ivHeader = findViewById(convertView, R.id.iv_header);
            holder.setTag(holder);
        } else {
            holder = (BaseViewHolder) convertView.getTag();
        }
        final String url = data.get(position).get("headerUrl");
       if (StringUtil.isNull(url)){
            holder .ivHeader.setBackgroundResource(R.drawable.default_head_icon);
       }else{
            ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri))
                    .setAutoRotateEnabled(true) 
                    .setLocalThumbnailPreviewsEnabled(true) //
                    .setProgressiveRenderingEnabled(true) //
                    .build();
            DraweeController controller = Fresco.newDraweeControllerBuilder()
                    .setImageRequest(imageRequest)
                    .setOldController(simpleDraweeView.getController())
                    .setAutoPlayAnimations(true)
                    .build();
            holder.ivHeader.setController(controller);
        }
        return convertView;
    }

When I scroll ListView to the end, the SimpleDraweeView displays the same image as the last screen image data. Anybody has the same problem?

Freddy
  • 764
  • 2
  • 6
  • 21
  • what is the `the last screen image data`? – Linh Dec 24 '15 at 09:19
  • six items will be displayed in screen, when I scroll listview to next six items,the 7th item's simpledraweeview display the 1th image data. – Freddy Dec 24 '15 at 09:23
  • please post full sourcecode in your adapter. you should write a log for check if 7th item load correct url or not. did the 7th item load same url as the 1th image data – Linh Dec 24 '15 at 09:36
  • I checked the log, the url is correct. the 7th item url is null and the 1th is the correct url – Freddy Dec 24 '15 at 09:51
  • I am not sure because I am never use if (StringUtil.isNull(url)). can you replace it by if (url == null){ – Linh Dec 24 '15 at 10:01
  • the same as :TextUtils.isEmpty(url) – Freddy Dec 24 '15 at 10:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98898/discussion-between-phan-vn-linh-and-freddy). – Linh Dec 24 '15 at 10:10

1 Answers1

0

Refer this code, when you expect your ListView data should be updated, don't forget to call notifydatasetchanged() which will reflet the changes in ListView.

I hope this helps :)

Community
  • 1
  • 1
Nakul
  • 1,313
  • 19
  • 26
  • ,thanks for helping, I didn't change the data,so there is no need to use notifydatasechanged() to refresh the listview,I just srcoll listview to the next screen item. – Freddy Dec 24 '15 at 09:26