title: Changing the Background on Item Selected of a Spinner Dropdown List
body: <p>I have a spinner that needs to change background images when touched (or pressed).</p>
  
  <p>I have the style set so that the correct image shows, but I cannot for the life of me get the background image to change.</p>
  
  <p><strong>My spinner code on my activity_main xml is this:</strong></p>
  
  <pre><code>&lt;Spinner
      android:layout_width="220dp"
      android:layout_height="wrap_content"
      android:id="@+id/spinner"
      style="@style/SpinnerDropdown1"
      android:layout_marginTop="450dp"
      android:layout_centerHorizontal="true"
      android:entries="@array/counties"/&gt;
  </code></pre>
  
  <p><strong>this is my @style/SpinnerDropDown1 code:</strong></p>
  
  <pre><code>&lt;Resources&gt;
    &lt;style name="SpinnerDropdown1" parent="android:TextAppearance.Widget.TextView.SpinnerItem"&gt;
      &lt;item name="android:background"&gt;@drawable/unpressed&lt;/item&gt;
      &lt;item name="android:textColor"&gt;#ffffff&lt;/item&gt;
      &lt;item name="android:divider"&gt;#ffffff&lt;/item&gt;
      &lt;item name="android:dividerHeight"&gt;1dp&lt;/item&gt;
    &lt;/style&gt;
  &lt;/Resources
  </code></pre>
  
  <p><strong>and here is my MainActivity.class</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements OnItemSelectedListener {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  final Spinner spinner = (Spinner) findViewById(R.id.spinner);
  
       final ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.counties, R.layout.my_spinner_items);
      adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
  
  
      spinner.setAdapter(adapter);
  
      spinner.setSelection(0);
  
      spinner.setOnTouchListener(new View.OnTouchListener() {
  
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              spinner.setBackgroundResource(R.drawable.pressed);
              return false;
          }
      });
  
      spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                                     int pos, long id) {
              switch(pos) {
  
                  case 1:
                      Intent j = new Intent (MainActivity.this, JasperOptions.class);
                      startActivity(j);
                      break;
                  case 2:
                      Intent k = new Intent(MainActivity.this, LakeOptions.class);
                      startActivity(k);
                      break;
                  case 3:
                      Intent l = new Intent(MainActivity.this, LaporteOptions.class);
                      startActivity(l);
                      break;
                  case 4:
                      Intent n = new Intent(MainActivity.this, NewtonOptions.class);
                      startActivity(n);
                      break;
                  case 5:
                      Intent p = new Intent(MainActivity.this, PorterOptions.class);
                      startActivity(p);
                      break;
              }
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
  
  
          }
  
      });
  
      }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
  
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
    }
  
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      return id == R.id.action_settings || super.onOptionsItemSelected(item);
  }
  
  
  @Override
  public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int pos, long l) {
  
  }
  
  @Override
  public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
  
   }
  }
  </code></pre>