<p>4.0 system Load Network pictures can not be sent to run in the main thread, otherwise it will report an exception, with a new thread method can be resolved: </p>
Package com.smalt.thread;
Import Java.io.InputStream;
Import Android.graphics.Bitmap;
Import android.graphics.BitmapFactory;
Import Android.os.AsyncTask;
Import Android.util.Log;
Import Android.widget.ImageView;
/**
* Display network picture in 4.0 system
*
* @author Administrator
*
*/
public class Downloadimage Exte NDS asynctask<string, Void, bitmap> {
ImageView imageview;
Public downloadimage (ImageView imageview) {
//TODO auto-generated constructor stub
This.imageview = I Mageview;
}
@Override
protected Bitmap doinbackground (String ... urls) {
//TODO auto-generated method stub
String url = urls[0];
Bitmap tmpbitmap = null;
try {
InputStream is = new Java.net.URL (URL). OpenStream ();
Tmpbitmap = Bitmapfactory.decodestream (IS);
} catch (Exception e) {
E.printstacktrace ();
log.i ("Test", E.getmessage ());
}
Return Tmpbitmap;
}
@Override
protected void OnPostExecute (Bitmap result) {
//TODO auto-generated stub
Imageview.setimagebitmap (result);
}
}
To load a picture method:
String Uribaidu = "Baidu_logo.gif";
New Downloadimage ((ImageView) Findviewbyid (R.ID.IV3)). Execute (URIBAIDU);