title: Setting up multiple spinners in android
body: <p>I have 2 spinners in my project and so far only have one spinner working! i am trying to have 2 spinners that when selected change the image in the imageview! the first spinner takes data from an array in the strings.xml and would also like the second array to do the same and update the imageview like the first one does! after trial and error i cant figure out how to do this and edited code back to the one spinner! </p>
  
  <pre><code>public class SpinnerRes extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final String[] spstr = getResources().getStringArray(R.array.spinnervalue);
          final Spinner sp = (Spinner)findViewById(R.id.spinner1);
  
          final ArrayAdapter&lt;String&gt; ar = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_dropdown_item,spstr);
          sp.setAdapter(ar);
  
          sp.setOnItemSelectedListener(new OnItemSelectedListener() {
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                                         int arg2, long arg3) {
                  final ImageView im = (ImageView)findViewById(R.id.imageView1);
                  String s=((TextView)arg1).getText().toString();
                  if(s.equals("A"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.a));
                  if(s.equals("A6"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.a6));
                  if(s.equals("A7"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.a7));
                  if(s.equals("Am"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.am));
  
                  if(s.equals("Am6"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.am6));
                  if(s.equals("Am7"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.am7));
                  if(s.equals("Amaj7"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.amaj7));
                  if(s.equals("img8"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img4));
  
                  if(s.equals("img9"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img1));
                  if(s.equals("img10"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img2));
                  if(s.equals("img11"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img3));
                  if(s.equals("img12"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img4));
  
                  if(s.equals("img13"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img1));
                  if(s.equals("img14"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img2));
                  if(s.equals("img15"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img3));
                  if(s.equals("img16"))
                      im.setImageDrawable(getResources().getDrawable(R.drawable.img4));
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                  // TODO Auto-generated method stub
              }
          });
  
      }
  }
  </code></pre>
  
  <p>The xml with the 2 spinners..</p>
  
  <pre><code>&lt;Spinner
      android:layout_height="40dp"
      android:layout_width="60dp"
      android:id="@+id/spinner1"
      android:layout_alignBottom="@+id/imageView"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_marginLeft="31dp"
      android:layout_marginStart="31dp"&gt;
  &lt;/Spinner&gt;
  &lt;Spinner
      android:layout_height="40dp"
      android:layout_width="50dp"
      android:id="@+id/spinner2"
      android:layout_alignTop="@+id/spinner1"
      android:layout_toRightOf="@+id/spinner1"
      android:layout_toEndOf="@+id/spinner1"
      android:layout_marginLeft="18dp"
      android:layout_marginStart="18dp"&gt;
  &lt;/Spinner&gt;
  </code></pre>
  
  <p>The strings.xml file with the 2 arrays</p>
  
  <pre><code>&lt;string-array name="spinnervalue"&gt;
      &lt;item&gt;A&lt;/item&gt;
      &lt;item&gt;A6&lt;/item&gt;
      &lt;item&gt;A7&lt;/item&gt;
      &lt;item&gt;Am&lt;/item&gt;
      &lt;item&gt;Am6&lt;/item&gt;
      &lt;item&gt;Am7&lt;/item&gt;
      &lt;item&gt;Amaj7&lt;/item&gt;
      &lt;item&gt;img8&lt;/item&gt;
      &lt;item&gt;img9&lt;/item&gt;
      &lt;item&gt;img10&lt;/item&gt;
      &lt;item&gt;img11&lt;/item&gt;
      &lt;item&gt;img12&lt;/item&gt;
      &lt;item&gt;img13&lt;/item&gt;
      &lt;item&gt;img14&lt;/item&gt;
      &lt;item&gt;img15&lt;/item&gt;
      &lt;item&gt;img16&lt;/item&gt;
  &lt;/string-array&gt;
  &lt;string-array name="spinnervalue2"&gt;
      &lt;item&gt;A&lt;/item&gt;
      &lt;item&gt;A6&lt;/item&gt;
      &lt;item&gt;A7&lt;/item&gt;
      &lt;item&gt;Am&lt;/item&gt;
      &lt;item&gt;Am6&lt;/item&gt;
      &lt;item&gt;Am7&lt;/item&gt;
      &lt;item&gt;Amaj7&lt;/item&gt;
      &lt;item&gt;img8&lt;/item&gt;
      &lt;item&gt;img9&lt;/item&gt;
      &lt;item&gt;img10&lt;/item&gt;
      &lt;item&gt;img11&lt;/item&gt;
      &lt;item&gt;img12&lt;/item&gt;
      &lt;item&gt;img13&lt;/item&gt;
      &lt;item&gt;img14&lt;/item&gt;
      &lt;item&gt;img15&lt;/item&gt;
      &lt;item&gt;img16&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>