Your explanation is not exactly right. ListView does not focus its children, it selects them. When the system enters touch mode (when the user touches the screen), the selection disappear.
> As an alternative you may want to remember the selected item by > overriding the onItemClick and onItemSelection methods and saving the > selected item's index, then use that to control your menu option > availability. This is not the proper way to do it. The menu should NOT contain contextual items; the menu should NOT contain items which depend on the selection state of a ListView. Contextual menus must be tied to long presses on the ListView. The menu (activated by the menu key) is a global menu meant for activity level actions only. > -- > Source: > http://stackoverflow.com/questions/569830/strange-listview-selection-behavior-on-android/ > > On Feb 18, 9:33 am, gsmd <[email protected]> wrote: >> Got an activity that extends ListActivity. >> The list is backed up by a custom adapter that extends BaseAdapter. >> -- >> getListView().setFocusable(true); >> getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); >> -- >> I do a simple (getSelectedItemPosition() == == >> ListView.INVALID_POSITION) check in onPrepareOptionsMenu() to disable >> the items that require an item to be selected. >> >> Now, what I do after launching the activity (the action takes place >> under emulator, ver.1.1) an what it looks like: >> 1) Hit menu - the menu items are disabled - OK >> 2) Select an item with mouse wheel and hit menu - the items get >> enabled - OK >> 3) Click anywhere outside the list, repeat 2). The items don't get >> enabled - WTF? >> 4) Start from scratch, select an item hitting Del and moving mouse. >> The result is the same as for 3). >> >> Why do these (3, 4) things keep happening to me? :) >> TIA. > > > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

