title: Android: Action based on combination of two spinner selections
body: <p>I have an activity with two spinners. One is the type of hair and the other is the color of the hair. I want for a picture (on a head) to change based on the two items selected selected from the spinners.</p>
  
  <p>Here's what it should do:</p>
  
  <ol>
  <li>Activity loaded (Spinners set to "Bald" and "Black")
  
  <ul>
  <li>Hair is bald.</li>
  </ul></li>
  <li>Change hair type to 'Male Short'
  
  <ul>
  <li>Hair changes to short black male hair.</li>
  </ul></li>
  <li>Change color to 'Blonde'
  
  <ul>
  <li>Hair changes to short blonde male hair.</li>
  </ul></li>
  </ol>
  
  <p>But step 3 doesn't work!!!</p>
  
  <p>Heres my code:</p>
  
  <pre><code>public class HeadZoom extends MainActivity implements AdapterView.OnItemSelectedListener{
  
  private Spinner hairSpinner;
  private Spinner hairColor;
  private String type;
  private String color;
  private ImageView imageView;
  private List&lt;String&gt; hairTypeArray = new ArrayList&lt;String&gt;();
  private List&lt;String&gt; hairColorArray = new ArrayList&lt;String&gt;();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.head_zoom);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      imageView = (ImageView) findViewById(R.id.head);
      type="Bald";
  
      hairSpinner = (Spinner) findViewById(R.id.hairSpinner);
      hairSpinner.setOnItemSelectedListener(this);
      List&lt;String&gt; hairTypeArray = new ArrayList&lt;String&gt;();
      hairTypeArray.add("Bald");
      hairTypeArray.add("Female Short");
      hairTypeArray.add("Female Medium");
        (...)
      ArrayAdapter&lt;String&gt; hairTypeAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_spinner_item, hairTypeArray);
      hairTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      hairSpinner.setAdapter(hairTypeAdapter);
  
      color = "Black";
  
      hairColor = (Spinner) findViewById(R.id.hairColor);
      hairColor.setOnItemSelectedListener(this);
      List&lt;String&gt; hairColorArray = new ArrayList&lt;&gt;();
      hairColorArray.add("Black");
      hairColorArray.add("Blonde");
      hairColorArray.add("Blue");
        (...)
      ArrayAdapter&lt;String&gt; hairColorAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_spinner_item, hairColorArray);
      hairColorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      hairColor.setAdapter(hairColorAdapter);
  }
  
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id){
      if(parent.getId()==hairSpinner.getId())
          type = hairTypeArray.get(position);
      else
          color = hairColorArray.get(position);
  
      switch(type){
          case "Bald":
              imageView.setImageResource((R.drawable.sw_head));
              break;
          case "Female Short":
              if(color=="Black")
                  imageView.setImageResource(R.drawable.fhair_short_black);
              else if(color=="Blonde")
                  imageView.setImageResource(R.drawable.fhair_short_blonde);
              else if(color=="Blue")
                  imageView.setImageResource(R.drawable.fhair_short_blue);
              else if(color=="Brown")
                  (...)
                  break;
          case "Female Medium":
              if(color=="Black")
                  imageView.setImageResource(R.drawable.fhair_med_black);
              else if(color=="Blonde")
                  imageView.setImageResource(R.drawable.fhair_med_blonde);
              else if(color=="Blue")
                  imageView.setImageResource(R.drawable.fhair_med_blue);
              else if(color=="Brown")
                  (...)
                  break;
          case "Female Long":
                 (...)
          default:
              break;
      }
  }
  
  public void onNothingSelected(AdapterView&lt;?&gt; parent){
  
  }
  </code></pre>
  
  <p>I need to be able to know what has been selected on both spinners at the same time.</p>
  
  <p>I get this error report when the activity (btw it crashes as soon as the activity opens)</p>
  
  <pre><code>    04-27 15:39:17.165 9934-9934/cameron.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: cameron.myapplication, PID: 9934
                                                                   java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
                                                                       at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
                                                                       at java.util.ArrayList.get(ArrayList.java:308)
                                                                       at cameron.myapplication.HeadZoom.onItemSelected(HeadZoom.java:83)
                                                                       at android.widget.AdapterView.fireOnSelected(AdapterView.java:931)
                                                                       at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:920)
                                                                       at android.widget.AdapterView.-wrap1(AdapterView.java)
                                                                       at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:890)
                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:148)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>