问题
I have a recyclerview
with diffutil
. Already I using Glide
to load images inside the ImageViews
.
on the onBindViewHolder
I call my function it's called loadImage(holder.view,item)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = getItem(position)
onLoadImage(holder.view, item)
}
In my loadImage I load the image inside the view.
private fun loadImage(view: View, item: MyItemModel) {
Timber.i("load item's image id: ${item.id} image is: ${item.image}")
Glide.with(context)
.asDrawable()
.load(item.image)
.into(view.main_image)
}
It works good, but when first time when It's loading the image than I swipe in the list, and the Images are shows like this:
So the Images are duplicated, but the last two image is different. It happens only if I swipe fast when It's loading. Log:
I/MyListAdapter: load image into : 6 image is: [B@25d0674
I/MyListAdapter: load image into : 7 image is: [B@e64ced4
I/MyListAdapter: load image into : 8 image is: [B@b384734
This is a Custom View. Context is that's view's context.
So the Images are different. What is the problem?
Any suggestion?
回答1:
I know its late but hope it will help someone. Override these two methods in your adapter.
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return position;
}
回答2:
Try clearing the image before loading a new one in your loadImage
method:
view.main_image.setImageBitmap(null)
Glide.with(...)
来源:https://stackoverflow.com/questions/52701438/glide-recyclerview-loading-duplicate-image