title: Android Volley response for loop
body: <p>I'm learning how to use Volley. I have the response logged to System.out.printIn successfully and seeing it in logcat for single item in the array. When I have multiple items, I'm struggling with FOR LOOP. I'm unable to figure out how to loop over the data. Could someone help please with showing me how to do it.</p>
  
  <p>My MainActivity</p>
  
  <pre><code>    package hfad.com.volley_listview_array;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  import com.android.volley.Request;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonObjectRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  public class MainActivity extends Activity {
      ArrayAdapter&lt;String&gt; adapter;
      ArrayList&lt;String&gt; items;
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          final TextView mTextView = (TextView) findViewById(R.id.textView);
  
          String url = "https://reqres.in/api/users?page=2";
  
          JsonObjectRequest jsonRequest = new JsonObjectRequest
                  (Request.Method.GET, url, new Response.Listener&lt;JSONObject&gt;() {
                      @Override
                      public void onResponse(JSONObject response) {
                          // the response is already constructed as a JSONObject!
                          try {
                              response = response.getJSONObject("data");
  
                              //for loop goes here? How? I get i already defined in scope
                              for (int i = 0, i &lt; response.length(), i++);
                              //String site = response.getString("first_name"),
                                //      network = response.getString("last_name");
                              //System.out.println("firstname: "+site+"\nLastname: "+network);
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }
                  }, new Response.ErrorListener() {
  
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          error.printStackTrace();
                      }
                  });
  
          Volley.newRequestQueue(this).add(jsonRequest);
  
  
      }}
  </code></pre>
  
  <p>And my activity_main.xml I don't need to display the results in a list. Just want all data to be piled one after the other.</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:padding="10dp"
      tools:context=".MainActivity"&gt;
  
  
      &lt;TextView
          android:id="@+id/textView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="TextView" /&gt;
       &lt;!--
      &lt;ListView
          android:id="@+id/listv"
          android:layout_width="match_parent"
          android:layout_height="89dp"&gt;&lt;/ListView&gt;
       --&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My data is from this test api <a href="https://reqres.in/api/users?page=2" rel="nofollow noreferrer">https://reqres.in/api/users?page=2</a></p>
  
  <pre><code>{"page":"2","per_page":3,"total":12,"total_pages":4,"data":[{"id":4,"first_name":"eve","last_name":"holt","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/marcoramires/128.jpg"},{"id":5,"first_name":"gob","last_name":"bluth","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/stephenmoon/128.jpg"},{"id":6,"first_name":"tracey","last_name":"bluth","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/bigmancho/128.jpg"}]}
  </code></pre>
  
  <p>I got data to be displayed in my logcat but it display the first item only. How to loop over all the records. I appreciate any help.</p>