title: Use this custom adapter with volley android
body: <p>I am working on an application in android. I have this code, and I tried to use it with volley so that I could load a json and add items to the list with the json, but I always end up doing it wrong... </p>
  
  <pre><code>package com.hmkcode.android;
  
  import java.util.ArrayList;
  import android.os.Bundle;
  import android.app.ListActivity;
  
  public class MainActivity extends ListActivity {
  
  public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
  
      // 1. pass context and data to the custom adapter
      MyAdapter adapter = new MyAdapter(this, generateData());
  
      //2. setListAdapter
      setListAdapter(adapter);
  }
  
  private ArrayList&lt;Item&gt; generateData(){
      ArrayList&lt;Item&gt; items = new ArrayList&lt;Item&gt;();
      items.add(new Item("Item 1","First Item on the list"));
      items.add(new Item("Item 2","Second Item on the list"));
      items.add(new Item("Item 3","Third Item on the list"));
  
      return items;
  }
  
  }
  </code></pre>
  
  <p>I tried to implement it like this but the static item that i set inside onResponse doesnt show, plus when I try to click on the items, the app ends up crashing</p>
  
  <pre><code>public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
  
      // 1. pass context and data to the custom adapter
      MyAdapter adapter = new MyAdapter(this, generateData());
  
      //2. setListAdapter
      setListAdapter(adapter);
  }
  
  private ArrayList&lt;Item&gt; generateData(){
      ArrayList&lt;Item&gt; items = new ArrayList&lt;Item&gt;();
      items.add(new Item("Item 1","First Item on the list"));
  
  
      RequestQueue queue = Volley.newRequestQueue(this);
      String url = "http://echo.jsontest.com/just/test/values/two";
  
      JsonObjectRequest jsObjRequest = new JsonObjectRequest(Method.GET, url, null, new Response.Listener&lt;JSONObject&gt;() {
  
          @Override
          public void onResponse(JSONObject response) {
             //my loop here
               items.add(new Item("Item 1","this is just a sample "));
             }
   }, new Response.ErrorListener() {
  
          @Override
          public void onErrorResponse(VolleyError error) {
              // TODO Auto-generated method stub
  
          }
      });
  
      queue.add(jsObjRequest);
  
  
      return items;
  }
  </code></pre>
  
  <p>EDIT: </p>
  
  <pre><code>    11-09 13:25:00.465:E/AndroidRuntime(10699): java.lang.IllegalStateException: 
  The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131230722, class android.widget.ListView) with Adapter(class android.janime.MyAdapter)]
  </code></pre>
  
  <p>the app crashes when I click one of the items on the list after onResponse has been executed .
  "Make sure the content of your adapter is not modified from a background thread, but only from the UI thread."</p>