<P> 4.0 the system cannot load network images in the main thread. Otherwise, an exception is reported. You can use the new thread method to solve the problem: </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 images in system 4.0
*
* @ Author Administrator
*
*/
Public class DownLoadImage extends AsyncTask <String, Void, Bitmap> {
ImageView imageView;
Public DownLoadImage (ImageView imageView ){
// TODO Auto-generated constructor stub
This. imageView = imageView;
}
@ 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 method stub
ImageView. setImageBitmap (result );
}
}
Image loading method:
String uriBaidu = "https://www.baidu.com/img/baidu_logo.gif ";
New DownLoadImage (ImageView) findviewbyid(r.id.iv3).exe cute (uriBaidu );