android - Why is my item Image in custom RecyclerView changing while scrolling? -


my app works fine, except saw items changing images while scrolling, somehow know that's recycling problem, dont know how solve it. tried code modifications in adapter, because think there, didn't succeed.

 public void onbindviewholder(customadapter_versionr.myviewholder holder, int position) {     //get current product of list     currentproduit = productlist.get(position);      try {         getimgurl = currentproduit.geturlimagelist_thumb().get(0);           picasso.with(context).load(getimgurl).fit().into(myimageview);         log.i("info", "image loaded");     } catch (exception e) {         myimageview.setimageresource(r.drawable.no_image);         log.e("error", "no image or image error");         e.printstacktrace();     } 

for download image, i'm using picasso, !

edit : full adapter

private product currentproduit; private imageview myimageview; private context context; private list<product> productlist; private string getagencyname, getimgurl; private list<string> geturllist_thumb; private list<string> geturllist_full; private imagebutton favorite_img_btn; private boolean star_isclicked;   public customadapter_versionr(context ctx, list<product> products) {     this.context = ctx;     this.productlist = products; }  public class myviewholder extends recyclerview.viewholder {     private textview title, descrip, price, agency, country, city, type, nbroom;     public myviewholder(view view) {         super(view);         //references layout         title = (textview) view.findviewbyid(r.id.title_product);         descrip = (textview) view.findviewbyid(r.id.descrip_product);         price = (textview) view.findviewbyid(r.id.price_product);         myimageview = (imageview) view.findviewbyid(r.id.img_product);         agency = (textview) view.findviewbyid(r.id.agency_product);         country = (textview) view.findviewbyid(r.id.country_product);         city = (textview) view.findviewbyid(r.id.city_product);         type = (textview) view.findviewbyid(r.id.type_product);         nbroom = (textview) view.findviewbyid(r.id.nbroom_product);     } }   @override public customadapter_versionr.myviewholder oncreateviewholder(viewgroup parent, int viewtype) {     view itemview = layoutinflater.from(parent.getcontext())             .inflate(r.layout.item_list_row, parent, false);     log.i("info", "creation ok");      return new myviewholder(itemview); }  @override public void onbindviewholder(customadapter_versionr.myviewholder holder, int position) {     //get current product of list     currentproduit = productlist.get(position);      try {         getimgurl = currentproduit.geturlimagelist_thumb().get(0);          picasso.with(context).load(getimgurl).fit().into(myimageview);         log.i("info", "image loaded");     } catch (exception e) {         myimageview.setimageresource(r.drawable.no_image);         log.e("error", "no image or image error");         e.printstacktrace();     }      holder.agency.settext(currentproduit.getnomagence();     holder.descrip.settext(currentproduit.getdescription());     holder.title.settext(currentproduit.gettitre());     holder.price.settext(currentproduit.getprix());     holder.nbroom.settext(currentproduit.getnbpieces());     holder.country.settext(currentproduit.getpays());     holder.city.settext(currentproduit.getville());     holder.type.settext(currentproduit.gettype_produit()); }  @override public int getitemcount() {     return productlist.size(); } 

edit: after researches, there's in onbindviewholder add, placeholder doesn't work, might doing soemthing wrong it..

it's because recycled view has previous item's information. have provide placeholder image myimageview.

consider setting placeholder image below:

myimageview.setimageresource(r.drawable.no_image); try {     // current try block } catch {     // current catch block } 

or providing placeholder image via picasso:

picasso.with(context)     .load(getimgurl)     .placeholder(r.drawable.user_placeholder)     .fit()     .into(imageview); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -