android - How to put condition on downloading image for listview? -
public avatardownloader(context context){ //make background thread low priority. way not affect ui performance photoloaderthread.setpriority(thread.norm_priority-1); //find dir save cached images if (android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted)) cachedir=new file(android.os.environment.getexternalstoragedirectory(),"/download/myapp/avatars/"); else cachedir=context.getcachedir(); if(!cachedir.exists()) cachedir.mkdirs(); } final int stub_id=r.drawable.ic_launcher; public void displayimage(string url, string profilepic, activity activity, imageview imageview) { if(cache.containskey(url)) imageview.setimagebitmap(cache.get(url)); else { //queuephoto(url, activity, imageview, profilepic); imageview.setimageresource(stub_id); } } private void queuephoto(string url, activity activity, imageview imageview, string profilepic) { //this imageview may used other images before. there may old tasks in queue. need discard them. photosqueue.clean(imageview); system.err.println("qph"+url); phototoload p=new phototoload(url, imageview, profilepic); synchronized(photosqueue.photostoload){ photosqueue.photostoload.push(p); photosqueue.photostoload.notifyall(); } //start thread if it's not started yet if(photoloaderthread.getstate()==thread.state.new) photoloaderthread.start(); }
here put code image downloader. want put code if image not available on server ic_launcher images shows. if image available show in listview.
i suggest use universal image loader image loading/showing related task. automatically handle memory management , can set own image if image not available on server.
Comments
Post a Comment