title: How to load images to ImageButton from url
body: <p>I need to get images from a server and load it to image-button.There are more than 50 images dynamically loading when application fragment starts. What is the best way to do this.Currently I'm using following code and when I run it application is stuck and also I followed <a href="http://www.androidhive.info/2012/07/android-loading-image-from-url-http/" rel="nofollow">Android Loading Image from URL (HTTP)</a> tutorial also, but it is not showing images when there are more than one images.</p>
  
  <p>this is the code I’m currently using when but application is freezing</p>
  
  <pre><code>private void setListParentItemInfo(View convertView,final IPTVChannel iptvChannel){
   ImageButton logoBtn = ((ImageButton) convertView.findViewById(R.id.channelLogo));
  
          String image_url="http://Channel.com.au/ChannelLogos/"+Channel.getLogoName();
    logoBtn.setImageBitmap(downloadBitmap(image_url));
  }
  
  
  private Bitmap downloadBitmap(String url) {
      // initilize the default HTTP client object
      final DefaultHttpClient client = new DefaultHttpClient();
  
      //forming a HttoGet request
      final HttpGet getRequest = new HttpGet(url);
      try {
  
          HttpResponse response = client.execute(getRequest);
  
          //check 200 OK for success
          final int statusCode = response.getStatusLine().getStatusCode();
  
          if (statusCode != HttpStatus.SC_OK) {
              Log.w("ImageDownloader", "Error " + statusCode +
                      " while retrieving bitmap from " + url);
              return null;
  
          }
  
          final HttpEntity entity = response.getEntity();
          if (entity != null) {
              InputStream inputStream = null;
              try {
                  // getting contents from the stream
                  inputStream = entity.getContent();
  
                  // decoding stream data back into image Bitmap that android understands
                  final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
  
                  return bitmap;
              } finally {
                  if (inputStream != null) {
                      inputStream.close();
                  }
                  entity.consumeContent();
              }
          }
      } catch (Exception e) {
          // You Could provide a more explicit error message for IOException
          getRequest.abort();
          Log.e("ImageDownloader", "Something went wrong while" +
                  " retrieving bitmap from " + url + e.toString());
      }
  
      return null;
  }
  </code></pre>
  
  <p>How can I fix this or any other why to do this?</p>