Picasso 的 RecyclerView 错误 Android
Error RecyclerView with Picasso Android
我有包含图像的 recyclerview。
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
// Get element from your dataset at this position and replace the contents of the view
// with that element
if(mEntities.get(position).url.equals("kosong")) {
Log.e("LOAD", "KOSONG " + position);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}
else{
Log.e("LOAD", "ISI " + position);
Picasso.with(mContext).load(mEntities.get(position).url).skipMemoryCache().into(viewHolder.imageView);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}
}
我成功地将图像加载到正确列表中的 recyclerview,但不知何故它在该 recyclerview 的另一个列表中重复。为什么?
感谢您的回答:)
据我了解,如果您的 url 包含 "kosong",您不应该显示任何图像,对吧?
但是您并没有清除它之前图像的图像视图。请记住,listviews/recycler 视图会循环使用它们的视图。因此,如果您在 imageview 上显示图像,然后(向上和向下滚动)该 imageview 被回收,它将包含为其设置的最后一个图像。
记得在不想使用图像时清除图像 (if(mEntities.get(position).url.equals("kosong"))
),方法如下:
viewHolder.imageView.setImageResource(android.R.color.transparent);
所以它应该是这样的:
if(mEntities.get(position).url.equals("kosong")) {
Log.e("LOAD", "KOSONG " + position);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
//we don't need to display an image here however it's possible that our listview contains another image from a recycled row. Let's clear it
viewHolder.imageView.setImageResource(android.R.color.transparent);
}
else{
Log.e("LOAD", "ISI " + position);
Picasso.with(mContext).load(mEntities.get(position).url).skipMemoryCache().into(viewHolder.imageView);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}
我有包含图像的 recyclerview。
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
// Get element from your dataset at this position and replace the contents of the view
// with that element
if(mEntities.get(position).url.equals("kosong")) {
Log.e("LOAD", "KOSONG " + position);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}
else{
Log.e("LOAD", "ISI " + position);
Picasso.with(mContext).load(mEntities.get(position).url).skipMemoryCache().into(viewHolder.imageView);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}
}
我成功地将图像加载到正确列表中的 recyclerview,但不知何故它在该 recyclerview 的另一个列表中重复。为什么?
感谢您的回答:)
据我了解,如果您的 url 包含 "kosong",您不应该显示任何图像,对吧?
但是您并没有清除它之前图像的图像视图。请记住,listviews/recycler 视图会循环使用它们的视图。因此,如果您在 imageview 上显示图像,然后(向上和向下滚动)该 imageview 被回收,它将包含为其设置的最后一个图像。
记得在不想使用图像时清除图像 (if(mEntities.get(position).url.equals("kosong"))
),方法如下:
viewHolder.imageView.setImageResource(android.R.color.transparent);
所以它应该是这样的:
if(mEntities.get(position).url.equals("kosong")) {
Log.e("LOAD", "KOSONG " + position);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
//we don't need to display an image here however it's possible that our listview contains another image from a recycled row. Let's clear it
viewHolder.imageView.setImageResource(android.R.color.transparent);
}
else{
Log.e("LOAD", "ISI " + position);
Picasso.with(mContext).load(mEntities.get(position).url).skipMemoryCache().into(viewHolder.imageView);
viewHolder.getTextDataView().setText(mEntities.get(position).data);
}