I have a ListView that normally is the singleChoice
choiceMode
. When the user long presses on an item, I want to enter an action mode that allows selecting multiple items so they can perform an action on any selected items.
I am able to configure the ListView
so that it is in singleChoice
mode and the user is able to select list items to display a details fragment next to it and have the list item itself shown in its activated state.
I am also able to configure the ListView
so that it is in the multipleChoiceModal
choiceMode
and performing a long press on an item starts the action mode and allows multiple selections, but now the ListView will not allow a single selection in the normal mode (no action mode).
How can I have a ListView that is in singleChoice
mode and then transition it to multipleChoiceModal
mode when an item is long pressed?
This is the closest I've been able to come up with:
- set the ListView to
singleChoice
mode - set the ListView's
OnItemLongClickListener
and in that listener:- set the ListView's
OnItemLongClickListener
tonull
- set the ListView's
choiceMode
tomultipleChoiceModal
- call
view.performClick()
on the item that was long pressed.
- set the ListView's
This approach has a couple problems.
- The action mode isn't started until the second time I long press on an item.
- When I call
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
inonDestroyActionMode
I get ajava.lang.StackOverflowError
because that method ends up trying to destroy the action mode as well (but we have no yet returned from the destroy).