Load ImageView from URL in Android

Load ImageView from URL in Android

Sometimes we need to show images in our Android application that are available in a remote server and can not be created as drawable resources. To load one of these images into an ImageView object, the image has to be turn from the URL into a bitmap. The following method solves this.

public boolean loadImageFromURL(String fileUrl, 
ImageView iv){
  try {

    URL myFileUrl = new URL (fileUrl);
    HttpURLConnection conn =
      (HttpURLConnection) myFileUrl.openConnection();

    InputStream is = conn.getInputStream();

    return true;

  } catch (MalformedURLException e) {
  } catch (Exception e) {

  return false;

Remember to grant the permission “android.permission.INTERNET” in the AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>
Share Button


  1. Josep Escobar

    Not work…
    10-10 00:56:11.547: W/View(17835): requestLayout() improperly called by android.widget.ListView{425e55b0 VFED.VC. ……ID 0,0-604,1134 #102000a android:id/list} during layout: running second layout pass

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.