Glide: Glide loading wrong images on RecyclerView

Created on 29 Jan 2018  路  7Comments  路  Source: bumptech/glide


Glide Version:
Verson 4.4.0


Integration libraries:
No

Device/Android Version:
Galaxy tab A

Issue details / Repro steps / Use case background:
so im rendering the images in a recyclerView.
but when scrolling down instead of only showing the progress dialog to wait the image to load, it is showing the previous loaded imagens. sometimes it takes a few seconds till the new image shows. Therefore staying with the wrong image for the wrong product.


Glide load line / GlideModule (if any) / list Adapter code (if any):

 protected void handleImage(final ProductsViewHolder viewHolder, Product item) {
        final String coverImage = item.getCoverImage();
        boolean loadImage = false;

        if (viewHolder.lastImageLoaded == null) {
            loadImage = true;
        } else if (!viewHolder.lastImageLoaded.equalsIgnoreCase(coverImage)) {
            loadImage = true;
        }

        if (loadImage) {
            if (viewHolder.imageProgress != null) {
                viewHolder.imageProgress.setVisibility(View.VISIBLE);
            }

            if (viewHolder.image != null) {
                GlideApp.with(UbookApp.getInstance())
                        .asBitmap()
                        .load(UiUtils.getImageUrlFromNameAndSize(coverImage, context.getResources().getInteger(R.integer.product_list_cover_image_size), context.getResources().getInteger(R.integer.product_list_cover_image_size)))
                        .error(R.drawable.ic_image_not_available)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, Transition transition) {
                                viewHolder.image.setImageBitmap(resource);

                                viewHolder.imageProgress.setVisibility(View.GONE);
                                viewHolder.image.setVisibility(View.VISIBLE);
                                viewHolder.lastImageLoaded = coverImage;
                            }

                            @Override
                            public void onLoadFailed(@Nullable Drawable errorDrawable) {
                                viewHolder.image.setImageDrawable(null);

                                viewHolder.imageProgress.setVisibility(View.GONE);
                                viewHolder.image.setVisibility(View.VISIBLE);
                                viewHolder.lastImageLoaded = "";
                            }
                        });
            }
        }
    }

Glide.with...

GlideApp.with(UbookApp.getInstance())
.asBitmap()
.load(UiUtils.getImageUrlFromNameAndSize(coverImage, context.getResources().getInteger(R.integer.product_list_cover_image_size), context.getResources().getInteger(R.integer.product_list_cover_image_size)))
.error(R.drawable.ic_image_not_available)
.into(new SimpleTarget() {
@Override
public void onResourceReady(Bitmap resource, Transition transition) {
viewHolder.image.setImageBitmap(resource);

                            viewHolder.imageProgress.setVisibility(View.GONE);
                            viewHolder.image.setVisibility(View.VISIBLE);
                            viewHolder.lastImageLoaded = coverImage;
                        }

                        @Override
                        public void onLoadFailed(@Nullable Drawable errorDrawable) {
                            viewHolder.image.setImageDrawable(null);

                            viewHolder.imageProgress.setVisibility(View.GONE);
                            viewHolder.image.setVisibility(View.VISIBLE);
                            viewHolder.lastImageLoaded = "";
                        }
                    });
        }


Layout XML:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.rey.material.widget.ProgressView
        android:id="@+id/imageProgress"
        android:layout_width="30dp"
        android:layout_height="30dp"
        app:pv_autostart="true"
        app:pv_progressStyle="@style/Widget.Ubook.ProgressView.Image"
        app:pv_circular="true"
        app:pv_progressMode="indeterminate"
        android:layout_gravity="center" />


    <ImageView
        android:id="@+id/image"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:visibility="gone" />


</FrameLayout>```

<!--
What is the error message that you got in the log?
You can find some help on diagnosing issues here: https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling
-->
**Stack trace / LogCat**:
```ruby
no error msg


screenRecord.zip

question

Most helpful comment

@prsolucoes how did you resolve this issue, I'm currently having same problem and tried all the Stackoverflow thread I could find but still no solution.

All 7 comments

See http://bumptech.github.io/glide/doc/getting-started.html#listview-and-recyclerview. You're not clearing previous loads in a number of cases.

You're also not clearing out the view in onLoadCleared in SimpleTarget. Why aren't you using a normal ViewTarget?

Hi @sjudd,

We work together, and we show a loading animation when the image start load, set the placeholder on image and when load finish or error happens we need hide the animation and show the error image.

With the default target we cant access other componentes to hide/show it, so, we need use the SimpleTarget.

Thanks.

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Can be closed. It was solved. Thanks.

Glad it was fixed. Just FYI, you can subclass ViewTarget or any of the existing ViewTargets and get access to exactly the same set of methods that you can on SimpleTarget.

@prsolucoes how did you resolve this issue, I'm currently having same problem and tried all the Stackoverflow thread I could find but still no solution.

Can be closed. It was solved. Thanks.

How did you solved?

Was this page helpful?
1 / 5 - 1 ratings

Related issues

StefMa picture StefMa  路  3Comments

kooeasy picture kooeasy  路  3Comments

mttmllns picture mttmllns  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

Anton111111 picture Anton111111  路  3Comments