title: How to populate Grid View with images from PHP MySql in Android?
body: <p>I want to retrieve all the images and populate GridView from PHP MySql Database. I'm using JSON parsing.But in my grid view is nothing display images from PHP and also nothing any error.So then why not show the images in Gridview in my application.What is wrong with the code. Thanks to appreciate.</p>
  
  <p>Here is my Adapter code.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  
  import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  public class GridViewAdapter extends BaseAdapter
  {
      private Context context;
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; mThumbIds;
  
      public GridViewAdapter (Context context,ArrayList&lt;HashMap&lt;String, String&gt;&gt; data )
      {
          this.context= context;
          mThumbIds= data;
      }
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return position ;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          ImageView imageView = new ImageView(context);
          imageView.setImageResource(mThumbIds.get(position).get("image"));
          imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
          imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
          return imageView;
  
      }
  }
  </code></pre>
  
  <p>Here is Activity code.</p>
  
  <pre><code>package com.photo_app;
  import java.util.ArrayList;
  import java.util.HashMap;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.GridView;
  
  public class Photo_Gallery extends Activity
  {
      JSONObject jsonobject;
      JSONArray jsonarray;
      GridView gridview;
      GridViewAdapter adapter;
      ProgressDialog mProgressDialog;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist;
      JSONParser jsonParser = new JSONParser();
      ProgressDialog pDialog;
      private String URL_PHOTO_GALLERY = "http://192.168.1.102/timesofindia/admin/photo_gallery.php";
  
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.photo_gallery);
          new DownloadJSON().execute();
      }
  
  
      private class DownloadJSON extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
  
              mProgressDialog = new ProgressDialog(Photo_Gallery.this);
              mProgressDialog.setTitle("Wait");
              mProgressDialog.setMessage("Loading...");
              mProgressDialog.setIndeterminate(false);
              mProgressDialog.show();
          }
  
          @Override
          protected Void doInBackground(Void... params) 
          {
  
              arraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
              jsonobject = JSONfunctions.getJSONfromURL(URL_PHOTO_GALLERY);
              System.out.println("Json String = " + jsonobject.toString());
  
  
              try
              {
                  jsonarray = jsonobject.getJSONArray("photo_gallary");
                  for (int i = 0; i &lt; jsonarray.length(); i++)
                  {
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                      jsonobject = jsonarray.getJSONObject(i);
                      map.put("flag", jsonobject.getString("image"));
                      arraylist.add(map);
                      Log.e("arraylist","=");
                  }
              } 
              catch (JSONException e)
              {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void args) {
  
              gridview = (GridView) findViewById(R.id.photoGallery);
              adapter = new GridViewAdapter();
              gridview.setAdapter(adapter);
              mProgressDialog.dismiss();
          }
      }
  }
  </code></pre>