title: android:load images from url and show in gridview
body: <p>i am making an app in which i have to get response from xml and i get image urls .Now i want to put images from urls into gridview but i dnt know how to extract images from urls and put in gridview.Any help will be appreciated.My code is as follows:</p>
  
  <pre><code>public class GalleryNewActivity extends Activity {
  
  private ProgressDialog dialog;
  GridView ga;
  Element e;
  Node elem;
   public List&lt;Drawable&gt; pictures;
  
  ImageView imageView;
  static final String PREFS_NAME = "MyPrefs";
  static final String USER_KEY = "user";
  static final String Name = "name";
  
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
         if(isNetworkconn()){
          new GetSPCAsyncTask().execute("");
      }else{
          showDialogOnNoInternet();
      }
    ga = (GridView)findViewById(R.id.Gallery01);
      ga.setAdapter(new ImageAdapter(this));
      imageView = (ImageView)findViewById(R.id.ImageView01);
      }
  
  
  
  public class ImageAdapter extends BaseAdapter {
      private Context mContext;
  
      public ImageAdapter(Context c) {
          mContext = c;
      }
  
      public int getCount() {
          return pictures.size();
      }
  
      public Object getItem(int position) {
          return null;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      // create a new ImageView for each item referenced by the Adapter
      public View getView(int position, View convertView, ViewGroup parent) {
          View v;
  
          if (convertView == null) { // if it's not recycled, initialize some
              // attributes
  
              LayoutInflater li = getLayoutInflater();
              v = li.inflate(R.layout.galleryitem, null);
              imageView = (ImageView)v.findViewById(R.id.thumbImage);
  
              imageView.setLayoutParams(new GridView.LayoutParams(200, 250));
  
              // imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setPadding(2, 5, 2, 5);
          } else {
              imageView = (ImageView) convertView;
          }
  
          imageView.setImageDrawable(pictures.get(position));
          imageView.setTag(pics[position]);
  
          return imageView;
      }
  
  
  private class GetPicsToNextPage extends AsyncTask&lt;String, String, String&gt;{
  
      @Override
      protected void onPreExecute() {
          // TODO Auto-generated method stub
          super.onPreExecute();
  
          dialog = ProgressDialog.show(GalleryNewActivity.this, "Please wait", "Loading...");
  
      }
  
      @Override
      protected String doInBackground(String... params) {
          // TODO Auto-generated method stub
          String str = null;
          try {
              Thread.sleep(2000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          return str;
      }
  
      @Override
      protected void onPostExecute(String result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
          dialog.dismiss();
  
          Intent intent = new Intent(getApplicationContext(), Flip3d.class);
          startActivity(intent);
  
      }
  }
  
  private boolean isNetworkconn(){
      ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      if (conMgr.getActiveNetworkInfo() != null &amp;&amp; conMgr.getActiveNetworkInfo().isAvailable() &amp;&amp; conMgr.getActiveNetworkInfo().isConnected()) {
          return true;
      }else{
          return false;
      }
  }
  
  private void showDialogOnNoInternet(){
      AlertDialog.Builder alt_bld = new AlertDialog.Builder(GalleryNewActivity.this);
      alt_bld.setTitle("Error.");
      alt_bld.setMessage("Your phone is not connected to internet.");
      alt_bld.setCancelable(false);
      alt_bld.setNeutralButton("OK", new DialogInterface.OnClickListener() {
  
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              dialog.dismiss();
          }
      });
      alt_bld.show();
  }
  
  
  //loader for dynamic starts
  private class GetSPCAsyncTask extends AsyncTask&lt;String, String, String&gt;{
  
      @Override
      protected void onPreExecute() {
          // TODO Auto-generated method stub
          super.onPreExecute();
          dialog = ProgressDialog.show(GalleryNewActivity.this, "Please wait", "Loading...");
      }
  
      @Override
      protected String doInBackground(String... params) {
          // TODO Auto-generated method stub
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          String xml = XMLfunctions.getXML();
          Document doc = XMLfunctions.XMLfromString(xml);
  
          NodeList nodes = doc.getElementsByTagName("Image");
  
          for (int i = 0; i &lt; nodes.getLength(); i++) {                           
              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();    
  
               e = (Element)nodes.item(i);
  
              //map.put("Image", XMLfunctions.getValue(e, "Image"));
  
              map.put("ImagePath", "Naam:" + XMLfunctions.getValue(e, "ImagePath"));
  
  
              map.put("ImageHeadline", "Headline: " + XMLfunctions.getValue(e, "ImageHeadline"));
              System.out.println(map.put("ImageHeadline", "Headline: " + XMLfunctions.getValue(e, "ImageHeadline")));
  
              map.put("ImageDesc", "Desc: " + XMLfunctions.getValue(e, "ImageDesc"));
              System.out.println(map.put("ImageDesc", "Desc: " + XMLfunctions.getValue(e, "ImageDesc")));
  
              mylist.add(map);
  
              Drawable d=LoadImageFromWebOperations();
              pictures.add(d);
          }       
  
      return xml;}
      @Override
      protected void onPostExecute(String result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
          dialog.dismiss();
  
              }
      private Drawable LoadImageFromWebOperations()
      {
          String path=XMLfunctions.getValue(e, "ImagePath");
            try{
               InputStream is = (InputStream) new URL(path).getContent();
               Drawable d = Drawable.createFromStream(is, "src name");
               Log.w("CREADO","CREADO");
               return d;
           }catch (Exception e) {
               System.out.println("Exc="+e);
               return null;
           }
    }
  }   
   }
  </code></pre>