title: Android: setSelection having no effect on Spinner
body: <p>I'm having some problems with setSelection on a Spinner. I set the value to be pre-selected when the spinner is shown in code, but it has no effect and the first alternative in the list is always selected. The code looks like this:</p>
  <pre><code>LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  final View dialogView = li.inflate(R.layout.edit_event, null);
  ...
  ArrayList&lt;String&gt; routes = new ArrayList&lt;String&gt;();
  // routes filled with values at runtime
  ...
  ArrayAdapter&lt;String&gt; aa = new ArrayAdapter&lt;String&gt;(GOFdroid.this, android.R.layout.simple_spinner_item, routes);
  aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
  Spinner destSpinner = (Spinner) dialogView.findViewById(R.id.edit_event_destination);
    
  String dest = events.get(pos).getDestination();
  int routesPos = routes.indexOf(dest);
  Log.d(TAG, &quot;Dest: &quot; + dest + &quot;, pos: &quot; + routesPos);
  destSpinner.setSelection(routesPos);
     
  destSpinner.setAdapter(aa);
  </code></pre>
  <p>The code works as intended except for the setSelection-part, and I just can't figure out why.</p>
  <p>The XML layout of the spinner looks like this (not the entire layout, only the spinner part):</p>
  <pre><code>// DESTINATION
  &lt;TextView
     android:layout_width=&quot;fill_parent&quot;
     android:layout_height=&quot;wrap_content&quot;
     android:text=&quot;Destination:&quot; /&gt;
  &lt;Spinner
     android:id=&quot;@+id/edit_event_destination&quot;
     android:layout_width=&quot;fill_parent&quot;
     android:layout_height=&quot;wrap_content&quot;
     android:prompt=&quot;@string/choose_dest&quot;
     android:layout_marginBottom=&quot;10dip&quot;
     android:text=&quot;&quot; /&gt;
  </code></pre>
  <p>Help is very much appreciated!</p>