title: How to use switch case with Spinner?
body: <p>I'm trying to figure out how to print a value using switch-case base off of what the user selected. I can easily print what the user selected in the spinner but I need the value that goes with it. I'm hoping I'm just missing something small in my code.</p>
  
  <pre><code>package com.example.test;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Spinner;
  
  public class Test extends Activity implements OnClickListener {
      EditText input1;
      Spinner answer;
      Object value;
      int yourInt = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          input1 = (EditText) findViewById (R.id.editText1);
          answer = (Spinner) findViewById (R.id.spinner1);
          ((Button) findViewById (R.id.button1)).setOnClickListener(this);
          answer.setOnItemSelectedListener(new OnItemSelectedListener() {
  
  
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
  
                  value = parent.getItemAtPosition(position);
                  switch (position) {
                  case 0:
                      yourInt = 1;
                      break;
  
                  case 1:
                      yourInt = 2;
                      break;
                  }
  
              }
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
              }
          });
      }
      public void onClick (View v) {
  
          input1.setText(yourInt);
      }
  }
  </code></pre>