title: Parse JSON data and put them into a gridview
body: <p>I'm developing an application in which I have to parse <code>JSON</code> data and have to put them in custom <code>gridview</code>. Here is what it should look like.</p>
  
  <p><img src="https://i.stack.imgur.com/25Kak.png" alt="How to display the gridview?"></p>
  
  <p>So far I have parsed my JSON data in asynctask and getting those values. Here is my code:</p>
  
  <pre><code>private class getRedeemData extends AsyncTask&lt;String, Void, String&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pdia = new ProgressDialog(AllPerksActivity.this);
          pdia.setMessage("Loading products. Please wait...");
          pdia.show();
      }
  
      @Override
      protected String doInBackground(String... args) {
          HttpParams params = new BasicHttpParams();
          params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
                  HttpVersion.HTTP_1_1);
          HttpClient httpClient = new DefaultHttpClient(params);
          HttpPost post = new HttpPost(
                  "MY API HERE..!!");
  
          post.setHeader("Content-Type", "application/x-www-form-urlencoded");
  
          try {
              post.setEntity(new StringEntity("client_id=" + client_id + "&amp;"
                      + "client_secret=" + clientSecretKey, HTTP.UTF_8));
  
              HttpResponse response = httpClient.execute(post);
              int i = response.getStatusLine().getStatusCode();
              System.out.println("HTTP Post status AllPerk Redeemption API: "
                      + i);
  
              BufferedReader in = new BufferedReader(new InputStreamReader(
                      response.getEntity().getContent()));
  
              // SB to make a string out of the inputstream
              StringBuffer sb = new StringBuffer("");
              String line = "";
              String NL = System.getProperty("line.separator");
              while ((line = in.readLine()) != null) {
                  sb.append(line + NL);
              }
              in.close();
  
              // the json string is stored here
              String result = sb.toString();
              System.out.println("Result Body: " + result);
              return result;
  
          } catch (Exception e) {
              // TODO: handle exception
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String result) {
          JSONObject jObject;
          try {
              jObject = new JSONObject(result);
  
              JSONArray jSearchData = jObject.getJSONArray("rewards");
  
              for (int i = 0; i &lt; jSearchData.length(); i++) {
  
                  JSONObject objJson = jSearchData.getJSONObject(i);
  
                  String rewardID = objJson.getString("rewardID");
                  String rewardType = objJson.getString("rewardType");
                  String rewardTitle = objJson.getString("rewardTitle");
  
                  System.out.println("Reward ID: " + rewardID);
                  System.out.println("Reward Type: " + rewardType);
                  System.out.println("Reward Tittle: " + rewardTitle);
              }
          } catch (Exception e) {
              // TODO: handle exception
          }
          pdia.dismiss();
      }
  }
  </code></pre>
  
  <p>Here is my XML for Gridview:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;GridView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/grid"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:horizontalSpacing="10dp"
  android:numColumns="2"
  android:scrollbarStyle="outsideOverlay"
  android:scrollbars="vertical"
  android:verticalScrollbarPosition="right"
  android:verticalSpacing="10dp" &gt;
  &lt;/GridView&gt;
  </code></pre>
  
  <p>Can some one tell my how to use adapter for this problem.</p>
  
  <p>Any kind of help will be appreciated.</p>