ImportJava.io.InputStream;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.os.AsyncTask;ImportAndroid.widget.ImageView; Public classDownloadimageextendsAsynctask<string, Void, bitmap>{ImageView ImageView; Publicdownloadimage (ImageView ImageView) {//TODO auto-generated Constructor stub This. ImageView =ImageView; } @OverrideprotectedBitmap doinbackground (String ... urls) {//TODO auto-generated Method StubString URL = urls[0]; Bitmap Tmpbitmap=NULL; Try{InputStream is=NewJava.net.URL (URL). OpenStream (); Tmpbitmap=Bitmapfactory.decodestream (IS); } Catch(Exception e) {e.printstacktrace (); } returnTmpbitmap; } @Overrideprotected voidOnPostExecute (Bitmap result) {//TODO auto-generated Method StubImageview.setimagebitmap (Result); } }
Write a tool class like this and then use it very simply
Downloadimage t=new downloadimage (Imgview);
T.execute (Imgurl);
If everyone who has a better way to welcome the discussion exchange.
Android easy to display network pictures