Jorge D Ortiz wrote: > Hi all, > > I have a problem when using getSeletedItemId() for a ListActivity. > The code should do something like this: > 1. User selects one row of the list. > 2. User invokes the menu option "Delete row". > 3. onOptionsItemSelected() handles that case and asks for > confirmation:
<snip> > It is unexpected to me that when calling getSelectedItemId() from > deleteSelectedRow() it returns -9223372036854775808. > However if I use this code instead it works fine: > case MENU_ID_DEL: > // Delete row > deleteSelectedRow(); > return true; > > Any ideas of my mistake? I'm not sure it's a "mistake" per se, but a side-effect of dialogs. As it turns out, I just ran into this issue an hour or two ago, so it's fresh in my mind. When you open the AlertDialog, the row in the ListActivity is no longer selected. I'd argue this is a bug -- opening a dialog should not affect the state of the underlying activity -- but there might be a good reason the Android team did it this way. What you need to do is save getSelectedItemId() before opening the AlertDialog (e.g., final long selection=getSelectedItemId()), so you have the proper value for use in the dialog's positive button callback. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.1 Published! --~--~---------~--~----~------------~-------~--~----~ 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] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

