Android - How to stop images reloading in Recyclerview when scrolling -
i creating app loading images internet in cards. using recyclerview listing purpose. downloading images, have tried picasso, universal-image-downloader , other custom methods everywhere have problem:
whenever scroll down , images in imageview getting reloaded. have kept condition check if imageview contains image doesn't seem work or code may faulty. not able find solution problem. below have attached 'onbindviewholder' function of code think problematic part. here images string arraylist containing image urls.
public viewholder oncreateviewholder(viewgroup parent, int viewtype) { view view = layoutinflater.from(parent.getcontext()) .inflate(r.layout.default_card, parent, false); viewholder viewholder; viewholder = new viewholder(view); return viewholder; } @override public void onbindviewholder(viewholder holder, int position) { string url = images.get(position); if (holder.imgview.getdrawable() != null) { //do nothing } else { imageloader.getinstance().displayimage(url, holder.imgview); } }
at first, there bug in code - have remove condition onbindviewholder. imageview instances has updated each time display.
@override public void onbindviewholder(viewholder holder, int position) { string url = images.get(position); imageloader.getinstance().displayimage(url, holder.imgview); } the reloading part:
the problem is, not using cache (in-memory, or disk based). not elabarote on lot, caching of images in collection views common problem , i'm sure quick stackoverflow search give lot of results.
just in particular - universal image does not have caching enabled default can turn on way.
displayimageoptions options = new displayimageoptions.builder() ... .cacheinmemory(true) .cacheondisk(true) ... .build(); imageloader.getinstance().displayimage(imageurl, imageview, options); // incoming options used or can set globally application, check docs.
Comments
Post a Comment