This example describes the Android implementation of ListView asynchronous loading. Share to everyone for your reference, specific as follows:
@Override public View getview (int position, View Convertview, viewgroup parent) {.....
Viewholder VH = null;
............
VH.mImageView.setTag (position); VH.mThumb.setImageDrawable (imageloader.loaddrawable (position, new Imagecallback () {public void Imageloa Ded (drawable imagedrawable, int position) {ImageView Imageviewbytag = (imageview) Mlist.findviewwithtag (posit
ION);
if (Imageviewbytag!= null) {imageviewbytag.setimagedrawable (imagedrawable);
}
}
}));
private static Lrucache<long, drawable> Mcache = new Lrucache<long, drawable> (100);
public class Asyncimageloader {public drawable loaddrawable (final int position, final Imagecallback callback) {
Drawable d = null;
D = mcache.get (position); if (d = = null) {final Handler handler=new Handler () {@Override public void Handlemessage (Mess
Age msg) { Callback.imageloaded ((drawable) msg.obj, position);
}
}; Thread t = new Thread () {public void run () {drawable drawable = utils.getdrawable (Mcontext, Positio
N, 1, Mmydefaulticon); drawable value = mcache.get (position);//cache may have been changed, so take a second if (value = = null) {Mcache.put P
Osition, drawable);
else {drawable = value;
} handler.sendmessage (Handler.obtainmessage (0,drawable));
};
};
T.setpriority (thread.min_priority);
T.start ();
return Mmydefaulticon;
else {return D;
}} public interface imagecallback{public void imageloaded (drawable imagedrawable, int position);
}
This was modified on the basis of a previous article http://www.jb51.net/article/90408.htm. Mainly to join the LRUCache
It was later found that the method was not very efficient because it was constantly opening up new threads. Finally, a background thread is added, and the task is removed from the LIFO queue.
For more information on Android-related content readers can view the site: "Android View tips Summary", "Android Programming activity Operating Skills Summary", "Android operation SQLite Database Skills Summary", " Android operation JSON format data tips summary, "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card Operation Summary", "Android Development introduction and Advanced Course", " Android Resource Operation tips Summary and the "Android Controls usage Summary"
I hope this article will help you with the Android program.