i have a RecyclerView with 30 rows of data. some rows have image that i get and show it with picasso. the problem is that, image box repeated every 8 rows even that row don't have image. i check that if image is empty don't show it, but show it yet.
JobAdapter.java
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final MyHolder myHolder = (MyHolder) holder;
JobClass current=data.get(position);
myHolder.name.setText(current.title);
myHolder.manager.setText(current.manager);
String phone= (String) new KerashDao(context).JobinfoGetValue(current.job_id.toString(),new KerashDao(context).SettingGetValue("phone").toString());
myHolder.phonecall.setText(phone.toString());
try {
if(!current.image.isEmpty()) {
Picasso.with(context)
.load(current.image)
.placeholder(R.drawable.icn_loading)
.into(myHolder.picture, new Callback() {
@Override
public void onSuccess() {myHolder.picture.setVisibility(View.VISIBLE);}
@Override
public void onError() {
myHolder.picture.setVisibility(View.GONE);
}
});
}
}catch (Exception ex){Log.i("JobAdapter2",ex.getMessage().toString()+"");}
}
RecyclerView
recycles the views that represent each row. This means that a given view will be re-used by another row once it scrolls off screen. Since you loaded an image into that view at some point, it will stick around until you clear it.
Add an else
clause to your if(!current.image.isEmpty())
statement that clears the image in your ImageView
.