OutOfMemoryError while using Universal Image Loader in gridview -
i have around 53 images show in gridview drwable. getting oom while doing that. started using universal image loader cache these images on disc , pull there..! still getting oom. here configuration
imageloader =imageloader.getinstance(); if (android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted)) cachedir=new file(android.os.environment.getexternalstoragedirectory(),"icons"); else cachedir=mcontext.getcachedir(); if(!cachedir.exists()) cachedir.mkdirs(); config= new imageloaderconfiguration.builder(mcontext) .memorycache(new weakmemorycache()) .denycacheimagemultiplesizesinmemory() .threadpoolsize(2) .offoutofmemoryhandling() .disccache(new unlimiteddisccache(cachedir)) .enablelogging() .build(); imageloader.init(config); options = new displayimageoptions.builder() .cacheondisc() .bitmapconfig(bitmap.config.rgb_565) .imagescaletype(imagescaletype.in_sample_int) .build();
and getview() of baseadapter
public view getview(int position, view convertview, viewgroup parent) { if(convertview==null) { viewholder holder=new viewholder(); inflator = mcontext.getlayoutinflater(); convertview = inflator.inflate(r.layout.imagelayout, null); holder.imageview=(imageview)convertview.findviewbyid(r.id.imgdet); convertview.settag(holder); } viewholder hold=(viewholder)convertview.gettag(); seek { imageloader.displayimage("drawable://" +mthumbids[position], hold.imageview, options,new imageloadinglistener() { @override public void onloadingstarted(string arg0, view arg1) { // todo auto-generated method stub } @override public void onloadingfailed(string arg0, view arg1, failreason arg2) { // todo auto-generated method stub } @override public void onloadingcomplete(string arg0, view arg1, bitmap arg2) { // todo auto-generated method stub } @override public void onloadingcancelled(string arg0, view arg1) { // todo auto-generated method stub } }); }catch(outofmemoryerror oom) { oom.printstacktrace(); } catch(exception ex) { ex.printstacktrace(); } homecoming convertview; }
please help me this.
always consider native way load drawables first.
imageview.setimageresource(...)
instead of using of imageloader
.
universal-image-loader
No comments:
Post a Comment