title: How to stop for loop execution until responce come in android
body: <p>I want to add each user response to my list listItem, inserting the response's specific key and value pair.  However, in this code, the first loop of getCat() executes 4 times ... then all responses get added to the last key those are 4.</p>
  
  <pre><code>public void getCat(){
  
      String url = "http://******/*****/*****.json";
      HashMap&lt;String, List&lt;CatType&gt; hmap=new HashMap&lt;String, ArrayList&lt;CatType&gt;&gt;();
      private List&lt;ListItem&gt; listItems;
      for(int i=1;i&lt;5;i++)
         {
  
         JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
               url, null, new Response.Listener&lt;JSONObject&gt;() {
  
         @Override
         public void onResponse(JSONObject response) {
             Log.d(TAG, "Response: " + response.toString());
             parseJsonFeed(response);
             listItems = new ArrayList&lt;ListItem&gt;();
             listItem.addAll(O_listItems);
             hmap.put("["+i+"]",listItem);
         }
      }, new Response.ErrorListener() {
  
         @Override
         public void onErrorResponse(VolleyError error) {
             Log.d(TAG, "Error: " + error.getMessage());
         }
      });
  
      // Adding request to volley request queue
      AppController.getInstance().addToRequestQueue(jsonReq);
      }
  }
  
  private void parseJsonFeed(JSONObject response) {
      try {
          JSONArray feedArray = response.getJSONArray("food");
          for (int i = 0; i &lt; feedArray.length(); i++) {
              JSONObject feedObj = (JSONObject) feedArray.get(i);
              OrderListItem item=new OrderListItem();
              item.setId(feedObj.getInt("id"));
              item.setImage(feedObj.getString("image"));
              item.setItem_name(feedObj.getString("name"));
              O_listItems.add(item);
          }
      } catch (JSONException e) {
          e.printStackTrace();
      }
  }
  </code></pre>