问题
So I have a submenu that I have for an options menu item. I want a list of checkable entries that the user can select/deselect as many as they want. The only problem I can't solve is how to prevent the option menu from closing when one of the checkboxes is clicked. I saw the performShortcut has a FLAG_PERFORM_NO_CLOSE flag, but I'm not sure how to use that method. I've tried many things, but I'm confused on where the keyevent is supposed to come from or if this is even the right method I should be looking at.
So tl;dr: How do I prevent options menus/submenus from closing when an option is selected?
回答1:
The way I would handle this is using the standard alert dialog class. In your menu handler, create an AlertDialog and pass an array of your options to the Builder.
The method you should pay attention to is AlertDialog.Builder.setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)
Pass an array to this method and put your submenu selection code in the ClickListener.
来源:https://stackoverflow.com/questions/3226710/android-checkable-submenu-options