title: android spinner if some item selected other spinner appear from derivative spinner 1
body: <p>I have database with 2 tables</p>
  
  <p>first table </p>
  
  <pre><code>id       jenis_barang
  1        kamera
  2        hp 
  3        laptop
  </code></pre>
  
  <p>second table</p>
  
  <pre><code>id        item_barang
  1         Canon
  1         sony 
  1         fujifilm
  2         xiaomi
  2         Samsung
  2         Vivo
  2         opppo
  3         Asus
  3         Toshiba
  3         Acer
  
  Spinner a =  Kamera, Hp, Laptop
  Spinner b =  Canon, Sony, Fujifilm, xiaomi, Samsung, Vivo, Oppo, Asus, Toshiba, acer
  </code></pre>
  
  <p>I try to search with button based on id and I'm success,
  and my trouble is, if I selected spinner 1, example I selected "kamera" and   spinner 2 show just same id based on "kamera".</p>
  
  <pre><code>    btnsearch.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String search =  searchdata.getText().toString().trim();
              setSpinner1 (search);
              setSpinner2 (search);
          }
      });
  
  
      spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              String name = spinner1.getSelectedItem().toString();
              Toast.makeText(MainActivity.this, name, Toast.LENGTH_SHORT).show();
          }
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          }
      });
  
  
      spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              String name = spinner2.getSelectedItem().toString();
             Toast.makeText(MainActivity.this, name, Toast.LENGTH_SHORT).show();
          }
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          }
      });
  }
  
  // set spinner pertama (1)
  public void setSpinner1(String kode) {
      connect = CONN(un, passwords, db, ip);
      String query1 = "select namabarang from Jenis_Barang ";  //where id = '"+kode+"'
      Log.e("query",""+query1);
      try {
          connect = CONN(un, passwords, db, ip);
          stmt = connect.prepareStatement(query1);
          rs = stmt.executeQuery();
  
          ArrayList&lt;String&gt; data = new ArrayList&lt;String&gt;();
          while (rs.next()) {
              String id = rs.getString(1);
              data.add(id);
              Log.e("idun",""+id);
          }
          String[] array = data.toArray(new String[0]);
          ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);
          spinner1.setAdapter(NoCoreAdapter);
      } catch (Exception e) {
          e.printStackTrace();
          Log.e("errora",""+e.getMessage());
      }
  
  }
  
  
  //set spinner ke dua
  public void setSpinner2(String kode) {
      connect = CONN(un, passwords, db, ip);
      String query2 = "select * from Item_Barang "; //where id = '"+kode+"'
      Log.e("query",""+query2);
      try {
          connect = CONN(un, passwords, db, ip);
          stmt = connect.prepareStatement(query2);
          rs = stmt.executeQuery();
  
          ArrayList&lt;String&gt; data = new ArrayList&lt;String&gt;();
          while (rs.next()) {
              String id = rs.getString(2);
              String kodeBarang = rs.getString(4);
              data.add(id + " - " + kodeBarang);
              Log.e("ijah",""+id);
          }
  
          String[] array = data.toArray(new String[0]);
          ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);
          spinner2.setAdapter(NoCoreAdapter);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>