开发者

Android checkable submenu options

开发者 https://www.devze.com 2023-01-07 10:06 出处:网络
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 t

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 whe开发者_如何学JAVAn 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消