title: Viewing of a list of images in Expandable List
body: <p>I have done a expandable list where child's (sub-items) are showing images from drawable folder or a text.</p>
  
  <p>I want to do same thing with images from web. I have therefore also used the asynctask to avoid <a href="http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html" rel="nofollow">NetworkOnMainThreadException</a></p>
  
  <p>This code is in my ExpandableListAdapter where i initialize the items and sub-items. Drawable and ImageView are globally defined so that all the functions can reach them without sending as parameters.</p>
  
  <pre><code>Drawable drawable;
  ImageView imgView;
  
  
  @Override
  public View getChildView(int groupPosition, int childPosition,
          boolean isLastChild, View convertView, ViewGroup parent) {
  
  String child = childList[groupPosition][childPosition];
  
      if(child.equalsIgnoreCase("none")){
          ImageView i = new ImageView(context);
          i.setImageResource(R.drawable.blank_image_for_view_business);
          i.setPadding(0, 0, 0, 0);
          return i ;          
      }
        else if(child.startsWith("http")){
           imgView = new ImageView(context);
          new asyTask();
          return imgView;
      }else{
          TextView tv = new TextView(context);
          tv.setText(childList[groupPosition][childPosition]);
          tv.setPadding(30, 0, 0, 0);
          return tv;
      }
  }
  
  private Drawable LoadImageFromWeb(String url){
        try{
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        }catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
        }
  }
  </code></pre>
  
  <p>And this is my asynchronous class:</p>
  
  <pre><code>private class asyTask extends AsyncTask&lt;String, Void, Integer&gt; {
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          //show a progress bar
      }
  
  
      @Override
      protected void onPostExecute(Integer result) {
          super.onPostExecute(result);
          imgView.setImageDrawable(drawable);   
      }
  
      @Override
      protected Integer doInBackground(String... params) {
          drawable  =  LoadImageFromWeb("http://www.ettinger.co.uk/var/ezflow_site/storage/images/collections/ettinger/ettinger-walkie-pen/lifestyle-navy-walkie-pen/navy-walkie-pen-gallery/wlkp_pens_navy-2/20569-2-eng-GB/wlkp_pens_navy-2.jpg"); 
          return 0;
      }
  </code></pre>
  
  <p>At the moment, in the expandable list i can only see images from drawable folder and textview's but there is no image from internet. What is the problem ? </p>