You must use setSelection(). But if you are in touch mode when the Activity starts (if you launched your activity using the mouse in the emulator for instance), then the selection will not show. Selection and focus do not exist in touch mode. That's the way it is, don't try to work around it :)
On Mon, Oct 6, 2008 at 12:47 PM, Mark Murphy <[EMAIL PROTECTED]> wrote: > > This is driving me up a wall... > > I want to have a GridView, containing four icons, and I want the first > icon to be pre-selected when the activity is opened. This wouldn't seem > too tough, but I'm obviously blanking on how to make it work. > > Some sample code: > > http://pastie.org/286143 > > The layout is just a GridView in a LinearLayout. The four icons > referenced in the Java are just some random icons. They all appear nice > in a row...just none are selected. > > I have grid.setSelection(0), but it does not seem to do anything. > > I have tried various ways of augmenting the code, including: > > -- calling grid.requestFocus() before grid.setSelection(0) > -- calling grid.invalidate() after grid.setSelection(0) > -- calling grid.requestLayout() after grid.setSelection(0) > -- delaying the grid.setSelection(0) via postDelayed() to ensure it gets > called after onCreate() finishes > -- putting the grid.setSelection(0) in onResume(), which is NOT what I > want, but I'm getting desperate > > The GridView selection works fine...once somebody presses the D-pad to > navigate the four icons. The selector (stock one from Android) shows up > quite nicely. I just want the first icon to be pre-selected, so the UI > is consistent -- there is *always* one icon highlighted. It is the only > widget in the layout, so there should be no question of who has the focus. > > What am I doing wrong? > > Thanks in advance! > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com > _The Busy Coder's Guide to Android Development_ Version 1.3 Published! > > > > -- Romain Guy www.curious-creature.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

