title: JSON array to auto complete text view in android
body: <p>i am working on an android app where i have to parse a Json array and adapt it to an auto complete text view. I am getting correct response from my server, since i am a fresher to android and Json parsing i am not getting how to parse that json array to array adapter and add it to auto complete text view.</p>
  
  <p>Can any body suggest me how to do it..?</p>
  
  <p>Response as follows.</p>
  
  <pre><code>[
  {
  city: "bng",
  area: "anagar",
  id: 510000032
  },
  {
  city: "bng",
  area: "bnagar",
  id: 510000021
  },
  {
  city: "bng",
  area: "cnagar",
  id: 510000037
  }
  ] 
  </code></pre>
  
  <p>i want area to be matched in my auto complete text view.</p>
  
  <p>I created auto complete text view in my layout file.</p>
  
  <p>This is how i am trying</p>
  
  <pre><code>    public class MainActivity extends Activity {
  
       List&lt;String&gt; responseList;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AutoCompleteTextView auto1 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
  
          new HttpGetTask().execute();
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_expandable_list_item_2, responseList);
          auto1.setAdapter(adapter);
      }
  
      private class HttpGetTask extends AsyncTask&lt;Void, Void, String&gt; {
  
          String URL = "http://xyz/cities.json?app_id=test";
          AndroidHttpClient mClient = AndroidHttpClient.newInstance("");
  
          @Override
          protected String doInBackground(Void... params) {
              HttpGet request = new HttpGet(URL);
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              try {
                  return mClient.execute(request, responseHandler);
              } catch (ClientProtocolException exception) {
                  exception.printStackTrace();
              } catch (IOException exception) {
                  exception.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(String result) {
              try {
                  JSONArray json = new JSONArray(result);
                  Log.v("ResponseCity", result);
  
                  responseList = new ArrayList&lt;String&gt;();
  
                  for (int i = 0; i &lt; json.length(); i++) {
                      final JSONObject e = json.getJSONObject(i);
                      String name = e.getString("area");
                      responseList.add(name);
  
                  }
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              if (null != mClient)
                  mClient.close();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>Any suggestions are appreciated...</p>