Further to my problem, I have successfully used " myListView.setSelection(0); " to position the place in the array list correctly. That is part of my problem solved. The remaining part of the problem is that I have been unable to turn on the highlight at this position. When I press the down key on the dpad the highlight turns on at the position I have set as outlined above. But when I try to use " myListView.getSelectedItemPosition() " without manually highlighting the position first, the app crashes. That is why I want to highlight an item by program control, to prevent such a crash. Thanks for your help so far. Is there any way to turn on the selection highlight?
----- Original Message ----- From: "Sean Hodges" <[email protected]> To: <[email protected]> Sent: Monday, June 01, 2009 3:20 AM Subject: [android-beginners] Re: Setting Focus by code in an array list > > Hello Mike, > > I'm not familiar with the code you are using, but I believe you want > to use setSelection() inside the "onCreate" method of the activity, > something like: > > findViewById(R.id.myListView).setSelection(0); > > See here for more info: > http://developer.android.com/reference/android/widget/ListView.html#setSelection%28int%29 > > If you're still struggling, post up the activity code so we can better > see what it is you are trying to do. > > > Regards, > > Sean > > > On Mon, Jun 1, 2009 at 10:19 AM, MMC2 <[email protected]> wrote: >> >> I am writing an app that is partly based on the ToDo Item example in >> the book "Professional Android Application Development by Reto Meier. >> I have an array list that lists data stored in a database. What I >> would like, is to be able to set the focus automatically to the first >> item by code when the list loads. The way things are at present, if I >> try to remove an item without manually highlighting it first, I get an >> error. Help please? >> > >> > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" 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-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

