beraybentesen / glide-xamarin-android

Glide Xamarin Binding
https://www.nuget.org/packages/Glide.Xamarin/
61 stars 14 forks source link

All images are the same ??! #20

Closed kilanny closed 6 years ago

kilanny commented 6 years ago

Hi.

I have a RecyclerView in which I am displaying items, each of which contain a thumb image. First I am populating the recycler view adapter with text-data, then I run a task (in background) that loops over the added items and downloads the bitmap of thumb from server and bind it, like this: ` var thumb = await ApiClient.GetVisitorThumbnail(mContext, 64, 64, new[] { holder.visitor.Id });

                mContext.RunOnUiThread(() =>
                {
                    Glide.With(mContext)
                        .Load(thumb[0].Thumbnail)
                        .Apply(RequestOptions.CircleCropTransform())
                        .Into(holder.thumbnail);
                });`

Where thumb[0].Thumbnail is byte[]. If I save this byte array to a png file, the image is correct.

Now all images are appearing the same !? What the wrong with me?

I am using the latest version 4.1

beraybentesen commented 6 years ago

This is not library-related problem but let me guess; When you say thumb[0].Thumbnail in Load method you're passing the same (first) object even it runs in a loop. So, use a List (If you're not already using) and any loop (foreach, for etc.) and pass each item to load.

Example:

`` public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { var item = dataModelList[position];

        var viewHolder = holder as RecyclerViewHolder;

        if (holder == viewHolder && viewHolder != null)
        {
            viewHolder.textView.Text = item.someString;

            Glide.With(context).Load(item.imageUrl).Into(viewHolder.imageView);
        }

}

kilanny commented 6 years ago

Dear, The same code snippet of me above works fine with version 3.x. Upgrading to 4.1 results with this error. I now switched back to version 3.7 and it works fine.