views:

89

answers:

1

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  A: 

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.

CodeFusionMobile
Is this method preferred over creating an entirely new activity, and declaring it as a dialog in my manifest, and then creating the checklist views myself? I know it's more work, and I know how to do both. But is one choice clearly better than the other?
Falmarri
@Falmarri If you don't need any customization beyond a list of text items, the standard alertdialog is the way to go. You should do it through the Activity's ShowDialog() method though. That handles a lot of the threading and control issues for you.
CodeFusionMobile