title: Spinner Selected one showing listview in android?
body: <p>In my app i have a Spinner with list of places(such as airport,mall..).When i click on Airport place from spinner,it should show list of airports auch as(sahara,juhu) below spinner in listview.I have tried this but it mixes list of places of airports and malls.
  Whts wrong in this.Plz help me.Below  is the json which i m using:-</p>
  
  <pre><code> {
    "PlacesList": {
  "PlaceType": [
    {
      "-Name": "Airport",
      "Places": {
        "Place": [
          {
            "name": "Juhu Aerodrome",
            "latitude": "19.09778",
            "longitude": "72.83083",
            "description": "Juhu Aerodrome is an airport that serves the metropolitan" 
          },
          {
            "name": "Chhatrapati Shivaji International Airport",
            "latitude": "19.09353",
            "longitude": "72.85489",
            "description": "Chhatrapati Shivaji International Airport  "
          }
        ]
      }
    },
    {
      "-Name": "Mall",
      "Places": {
        "Place": [
          {
            "name": "Infinity",
            "latitude": "19.14030",
            "longitude": "72.83180",
            "description": "This Mall is one of the best places for all types of brand"
          },
          {
            "name": "Heera Panna",
            "latitude": "18.98283",
            "longitude": "72.80897",
            "description": "The Heera Panna Shopping Center is one of the most popular"
          }
        ]
      }
    }
  ]
    }
  } 
  </code></pre>
  
  <p>///////////////////////////////////</p>
  
  <pre><code>public class PlaceDemo extends Activity 
  {
  private String jString;
  private Spinner spinner;
  private ListView lister2;
  
  private ByteArrayInputStream json;
  private ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist;
  private PlaceType pttype;
  
  private List&lt;PlaceType&gt; results;
  private Place place;
  private List&lt;Place&gt; places;
  private ArrayList&lt;HashMap&lt;String, String&gt;&gt; placelist;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      try 
      {
          InputStream is = getAssets().open("place_file.json");
  
          Writer writer = new StringWriter();
          char[] buffer = new char[1024];
          try 
          {
              Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
              int n;
              while ((n = reader.read(buffer)) != -1) 
              {
                  writer.write(buffer, 0, n);
              }
          } 
          finally 
          {
              is.close();
          }
  
          jString = writer.toString();
          System.out.println(jString);
  
  
      } 
      catch (IOException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  
      spinner = (Spinner) findViewById(R.id.spinner);
      lister2 = (ListView) findViewById(R.id.ListView2);
  
          try 
          {
              json = new ByteArrayInputStream(jString.getBytes("UTF-8"));
          } 
          catch (UnsupportedEncodingException e1) 
          {
              e1.printStackTrace();
          }
  
          try
          {
  
               Gson gson = new Gson();
  
                          Reader reader = new InputStreamReader(json);
  
                          Places response = gson.fromJson(reader,Places.class);
  
                          results = response.plist;
  
          } 
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
          mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          placelist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          try
          {   
              for (int i = 0; i &lt; results.size(); i++) 
              {
                  pttype = results.get(i);
  
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();    
  
                          map.put("name",pttype.name);
  
                          mylist.add(map);
  
              }
  
              for (int i = 0; i &lt; results.size(); i++) 
              {
                  pttype = results.get(i);
  
                          HashMap&lt;String, String&gt; map1 = new HashMap&lt;String, String&gt;();   
  
                          places = pttype.place;
  
                          for (int j = 0; j &lt; places.size(); j++) 
                          {
                              place =places.get(j);
  
                              map1.put("desc",place.desc);
                              map1.put("lat",place.lat);
                              map1.put("lng",place.lng);
                              map1.put("name1",place.name);
  
                              placelist.add(map1);                
                          }
  
  
              }
          }
          catch (Exception e1) 
          {
                      e1.printStackTrace();
          }
  
          SpinnerAdapter adapter = new SpinnerAdapter(this, mylist , R.layout.row, 
                      new String[] { "name" }, 
                      new int[] { android.R.id.text1});
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
           SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
  
                  public boolean setViewValue(View view, Object data,
                          String textRepresentation) {
  
                      TextView textView = (TextView) view;
                      textView.setText(textRepresentation);
                      return true;
                  }
              };
  
          adapter.setViewBinder(viewBinder);
            spinner.setAdapter(adapter);
  
          spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
          {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                      int position, long arg3)
              {
  
                  String[] lister = null;
                  switch (position) 
                  {
                  case 0:
                      String[] airport = new String[] { "name1" };
                      lister = airport ;
  
                      break;
                  case 1:
                      String[] mall = new String[] { "name1" };
                      lister = mall ;
  
                      break;
  
                  }
  
  
                  lister2.setAdapter(new PlaceAdapter(PlaceDemo.this, placelist , R.layout.row, 
                          lister, 
                          new int[] { R.id.tt1}));
                  lister2.setVisibility (View.VISIBLE);
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                  // TODO Auto-generated method stub
  
              }
          });
  
  }
  
  
  public class PlaceAdapter extends SimpleAdapter 
  {
  
      private ArrayList&lt;HashMap&lt;String, String&gt;&gt; results;
  
      public PlaceAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; data, int resource, String[] from, int[] to) 
      {
          super(context, data, resource, from, to);
          this.results = data;
      }
  
      public View getView(int position, View view, ViewGroup parent)
      {
  
        View v = super.getView(position, view, parent);
  
          if (v == null) 
          {
              LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = vi.inflate(R.layout.row, null);
          }
  
          TextView id = (TextView) v.findViewById(R.id.tt1);
          id.setText(results.get(position).get("name1"));
  
          return v;
      }
  
  }
  
  public class SpinnerAdapter extends SimpleAdapter 
  {
  
      private ArrayList&lt;HashMap&lt;String, String&gt;&gt; results;
  
      public SpinnerAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; data, int resource, String[] from, int[] to) 
      {
          super(context, data, resource, from, to);
          this.results = data;
      }
  
      public View getView(int position, View view, ViewGroup parent)
      {
  
        View v = super.getView(position, view, parent);
  
          if (v == null) 
          {
              LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = vi.inflate(R.layout.row, null);
          }
  
          TextView id = (TextView) v.findViewById(R.id.tt1);
          id.setText(results.get(position).get("name"));
  
          return v;
      }
  
  }
   }
  </code></pre>