title: Call JSON on Spinner OnItemSelected and display data into another Spinner
body: <p>I am making an android app in which I am using two spinners. In first spinner I am displaying data from JSON which I've done successfully. Now by clicking an item of first spinner I need to display data from another JSON service into second spinner.</p>
  
  <p><strong>First Service (I am displaying <code>city_name</code> from this service on first spinner):</strong></p>
  
  <pre><code>{"result":{"data":[{"city_id":"16","city_name":"\u00c4ngelholm"},
  {"city_id":"23","city_name":"B\u00e5stad"},
  {"city_id":"22","city_name":"Halmstad"},
  {"city_id":"19","city_name":"H\u00f6gan\u00e4s"},{"city_id":"20","city_name":"Helsingborg"},
  {"city_id":"15","city_name":"Klippan"},
  {"city_id":"24","city_name":"Kungsbacka"},
  {"city_id":"21","city_name":"Laholm"},{"city_id":"18","city_name":"Landskrona"}],
  "status":"true","description":""}} 
  </code></pre>
  
  <p><strong>Second Service:</strong></p>
  
  <pre><code>{"result":{"data":[{"category_id":"18","category":"Aff\u00e4rsverksamhet",
  "city_id":"16","city_name":"\u00c4ngelholm"},{"category_id":"19","category":"\u00d6vrigt",
  "city_id":"16","city_name":"\u00c4ngelholm"},{"category_id":"13","category":"Bostad",
  "city_id":"16","city_name":"\u00c4ngelholm"},{"category_id":"15","category":"Elektronik",
  "city_id":"16","city_name":"\u00c4ngelholm"},{"category_id":"12","category":"F\u00f6r hemmet","city_id":"16","city_name":"\u00c4ngelholm"},{"category_id":"11","category":"Fordon",
  "city_id":"16","city_name":"\u00c4ngelholm"},
  {"category_id":"16","category":"Fritid &amp; Hobby",
      "city_id":"16","city_name":"\u00c4ngelholm"}],
      "status":"true","description":""}}
  </code></pre>
  
  <p>As you can see in both services <code>city_id</code> and <code>city_name</code> are common fields. If I select <code>city_name</code> from first spinner it will match through <code>city_id</code> or <code>city_name</code> and display <code>category</code> against that <code>city_name</code>.</p>
  
  <p>Below is my code I have tried.</p>
  
  <pre><code> private class AllCities extends AsyncTask&lt;String, String, JSONObject&gt;
      {
          @Override
          protected void onPreExecute() 
          {
              super.onPreExecute();
          }
  
          @Override
          protected JSONObject doInBackground(String... params) 
          {
              try
              {
                  HttpClient client = new DefaultHttpClient();
                  HttpPost post = new HttpPost("url of First Service");
  
                  HttpResponse resp = client.execute(post);
  
                  HttpEntity entity = resp.getEntity();
  
                  String response = EntityUtils.toString(entity);
  
                  return new JSONObject(response);
  
              }
  
              catch(Exception ex)
              {
                  ex.printStackTrace();
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(JSONObject result) 
          {
              super.onPostExecute(result);
  
  
              if(result != null)
              {
                  myList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
                  if(! result.has("false"))
                  {
                      try
                      {
                          JSONObject object = result.getJSONObject("result");
  
  
                          JSONArray array = object.getJSONArray("data");
  
                          stringArray = new ArrayList&lt;String&gt;();
  
                          for(int i=0; i&lt;array.length(); i++)
                          {   
                              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                              map.put("city_id", array.getJSONObject(i).getString("city_id"));                            
                              map.put("city_name", array.getJSONObject(i).getString("city_name"));
                              myList.add(map);
  
                              stringArray.add(array.getJSONObject(i).getString("city_name"));
  
  
                          }
  
                          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(PostAdds.this, 
                                  android.R.layout.simple_spinner_item, stringArray);
                          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                          spinner_city.setAdapter(adapter);
  
                      }
  
                      catch(Exception ex)
                      {
                          ex.printStackTrace();
                      }
  
                  }
  
              }
  
              else if(result == null)
              {
                  Toast.makeText(PostAdds.this, 
                          "Hittade inga Detaljer Vänligen Kontrollera din Internet-anslutning", 
                          Toast.LENGTH_LONG).show();
              }
  
          }
      }
  
   @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) 
      {   
          //what am I suppose to do here????
  
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) 
      {
  
  
      }
  </code></pre>