Android checkable submenu options

ⅰ亾dé卋堺 提交于 2019-11-28 04:31:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!