Strange behaviour of images in RecyclerView

后端 未结 3 1058
忘掉有多难
忘掉有多难 2020-12-23 09:52

I am using android.support.v7.widget.RecyclerView to show simple items containing text and in some cases also images. Basically I followed the tutorial from here https://dev

3条回答
  •  旧时难觅i
    2020-12-23 10:36

    I think you need to add an else clause to your if ( object.has("image") ) statement in the onBindViewHolder(ViewHolder holder, int position) method, setting the image to null:

    holder.image.setImageDrawable(null);
    

    I think the documentation for onBindViewHolder describe it best why this is necessary:

    Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

    You should always assume that the ViewHolder passed in needed to be completely updated :)

提交回复
热议问题