android ImageView in RecyclerView loads the same image in random positions -
the recyclerview using has imageview background emptyheart image initially.when touched should change filledheart image.i add checked positions arraylist using getadapterposition() of recyclerviewadapter , remove if arraylist contains touched position.but when scroll imageview's background changed @ random positions.
recycleradapter:
public class shopofferrecycadapter extends recyclerview.adapter<shopofferrecycadapter.shopofferholder> { view view;int counter=0;arraylist checkeditems; @override public shopofferholder oncreateviewholder(viewgroup parent, int viewtype) { view= layoutinflater.from(parent.getcontext()).inflate(r.layout.shop_offers_recycler_adapter,parent,false); return new shopofferholder(view); } @override public void onbindviewholder(shopofferholder holder, int position) { displayimageoptions options = new displayimageoptions.builder().showimageonloading(r.drawable.mobile) .showimageforemptyuri(r.drawable.mobile).showimageonfail(r.drawable.mobile).cacheinmemory(true).cacheondisk(true) .considerexifparams(true).bitmapconfig(bitmap.config.rgb_565).build(); imageloader.getinstance().displayimage("http://dress-trends.com/wp-content/uploads/2015/10/fashion-clothing-for-men-spring-summer-2016-61.jpg",holder.imageview,options); } @override public int getitemcount() { return 10; } public class shopofferholder extends recyclerview.viewholder{ imageview imageview,fav; public shopofferholder(view itemview) { super(itemview); checkeditems=new arraylist(); imageview=(imageview) itemview.findviewbyid(r.id.product_img); fav=(imageview) itemview.findviewbyid(r.id.fav); fav.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if(checkeditems.size()>0&&checkeditems.contains(getadapterposition()+1)==true) { checkeditems.remove(getadapterposition()+1); fav.setimageresource(r.drawable.heartnofill); log.e("position removed", integer.tostring(getadapterposition()+1)); } else if(checkeditems.contains(getadapterposition())==false){ fav.setimageresource(r.drawable.heartfill); checkeditems.add(getadapterposition()+1); log.e("pos added",integer.tostring(getadapterposition()+1)); // if(checkeditems.contains(getadapterposition()){ // checkeditems.remove(getadapterposition()); // log.e("position removed",integer.tostring(getadapterposition())); } return false; } }); } } }
try in onbindviewholder method
holder.setisrecyclable(false);
as can understand name of method, tell recycler view stop recycling view holder.
this can cause performance issues in cases
but looking @ getcount method in above code snippet seems have less elements deal :)
Comments
Post a Comment