1.
2. Implementing the Code
1. Configure permissions It's one thing that's easy to forget.
<uses-permission android:name= "Android.permission.INTERNET"/> <!--access to INTERNET permissions--
2. Layout files
<imageview android:id= "@+id/imageview1" android:layout_width= "wrap_content" android:layout_ height= "Wrap_content" android:layout_marginbottom= "196DP" android:src= "@drawable/ic_launcher"/>
3. java files
public class Mainactivity extends Activity {private list<string> urllist = new arraylist<string> ();p rivate Bi TMap bitmap;imageview imageview;imageview imageview2;private URL url = null;/** * notification message */handler Handler = new Handler () {@Overridepublic void Handlemessage (Message msg) {if (Msg.what = = 0x9527) {//display pictures downloaded from the Web imageview.setimagebitmap (bitmap );}}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); ImageView = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);//Create and start a new thread to download pictures from the network Urllist.add (" New Thread () {@Overridepublic void run () {try {//Http://pic1.nipic.com/2008-10-22/2008102293811572_2.jpg Create a URL object url = new URL (urllist.get (0));//open URL corresponding to the resource input stream InputStream is = Url.openstream ();//parse the picture from the InputStream stream bitmap = Bitmapfactory.decodestream (IS);//Imageview.setimagebitmap (bitmap);//Send a message informing the UI component to display a picture handler.sendemptymessage ( 0x9527);//Close input stream is.close ();} catch (Exception e) {e.printstacktrace ();}}}. Start ();}}
Android-ImageView Get online picture resources through bitmap