title: Am trying to set an arrayList in a list view and only the last item appears in the list view
body: <p>I just cant see what is wrong with my code even after following all the other answers here. Can someone please look at my code and tell me why the list view only displays the last item in the loop
  Here is my code</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_my_appointments);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      pDialog = new ProgressDialog(this);
      pDialog.setCancelable(false);
      db = new SQLiteHandler(getApplicationContext());
      listview = (ListView)findViewById(R.id.appointmentList);
      //  cancel request tag
      String tag_string_req = "req_appointments";
  
      pDialog.setMessage("fetching appointments...");
      showDialog();
  
      StringRequest strReq = new StringRequest(Request.Method.POST,
              AppConfig.URL_FETCH_APPOINTMENTS, new Response.Listener&lt;String&gt;() {
  
          @Override
          public void onResponse(String response) {
              Log.d(TAG, "Appointment fetch response: " + response.toString());
              hideDialog();
  
              try {
                  JSONObject jObj = new JSONObject(response);
                  boolean error = jObj.getBoolean("error");
                  if (!error) {
                      JSONArray appointments = jObj.getJSONArray("appointments");
                      //Log.d(TAG, String.valueOf(appointments.length()));
                      int count=appointments.length();
                      String fullAppointment="";
                      for (int i=0;i&lt;count;i++){
                          JSONObject jsonObj2 = appointments.getJSONObject(i);
                          String date = jsonObj2.getString("date");
                          String status=jsonObj2.getString("status");
                          String timestamp=jsonObj2.getString("timestamp");
                          String appointmentStatus="";
                          if (status.matches("PENDING")){
                              appointmentStatus="This appointment is still pending and has not been confirmed by the doctor";
                          }else{
                              appointmentStatus="This appointment has already been confirmed by the doctor";
                          }
                          //Log.d(TAG,date+":"+status+":"+timestamp);
                          fullAppointment="Date of consultation: "+date +"\n"+ appointmentStatus +"\n"+ "Booked on date :"+timestamp;
                          //myList.add(fullAppointment);
                          adapter.add(fullAppointment);
                          adapter.notifyDataSetChanged();
  
                      }
  
  
                  } else {
  
                      String errorMsg = jObj.getString("error_msg");
                      Toast.makeText(getApplicationContext(),
                              errorMsg, Toast.LENGTH_LONG).show();
                      Intent intent = new Intent(
                              MyAppointments.this,
                              HomeActivity.class);
                      startActivity(intent);
                      finish();
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
          }
      }, new Response.ErrorListener() {
  
          @Override
          public void onErrorResponse(VolleyError error) {
              Log.e(TAG, "Appointment Error: " + error.getMessage());
              Toast.makeText(getApplicationContext(),
                      error.getMessage(), Toast.LENGTH_LONG).show();
              hideDialog();
          }
      }) {
  
          @Override
          protected Map&lt;String, String&gt; getParams() {
              HashMap&lt;String, String&gt; user = db.getUserDetails();
              String userID = user.get("uid");
              // Posting params to register url
              Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
              params.put("userID", userID);
  
              return params;
          }
  
      };
  
      // Adding request to request queue
      myConnection.getInstance().addToRequestQueue(strReq, tag_string_req);
  
      adapter= new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,0);
      listview.setAdapter(adapter);
  
  }
  </code></pre>
  
  <p>This is what i get when i print the arrayList in console
  <a href="https://i.stack.imgur.com/odeyb.jpg" rel="nofollow noreferrer">enter image description here</a></p>