title: Set highlighted item in GridView on Android
body: <p>Sometimes I am really amazed to see that simple things have hard to find solutions.</p>
  
  <p>I have a <code>GridView</code> with 6 columns and multiple rows. Each item is a square having a color as background. When I select an item, it gets highlighted as the <code>listSelector</code> is set</p>
  
  <pre><code>&lt;GridView
          android:id="@+id/listFontColors"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_gravity="center_horizontal"
          android:layout_margin="8dip"
          android:drawSelectorOnTop="true"
          android:gravity="center"
          android:horizontalSpacing="3dp"
          android:listSelector="@drawable/color_list_selected"
          android:numColumns="6"
          android:padding="0dip"
          android:scrollbars="none"
          android:stretchMode="columnWidth"
          android:verticalSpacing="3dp" /&gt;
  </code></pre>
  
  <p>When I open the layout, containing the <code>GridView</code> I want to highlight the previous selected item. As the adapter behind it has an <code>ArrayList&lt;Object&gt;</code> is easy to find what position needs to be highlighted. The problem is performing actual highlight.</p>
  
  <p>I did a lot of testing:</p>
  
  <pre><code>listColors.requestFocus();
  listColors.setSelection(9);
  
  if (v != null) {
      v.requestFocus();
      v.setPressed(true);
      v.setSelected(true);
  }
  listColors.performItemClick(listColors, 9, listColors.getItemIdAtPosition(9));
  </code></pre>
  
  <p>None of this worked. Any ideas?</p>