Android的辨认子菜单选项 [英] Android checkable submenu options

查看:146
本文介绍了Android的辨认子菜单选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个子菜单,我有一个选项菜单项。我希望用户可以选择/取消尽可能多的,因为他们想辨认的条目列表。唯一的问题我解决不了是怎么prevent选项菜单中的关闭被点击复选框中的一个时。只见performShortcut有FLAG_PERFORM_NO_CLOSE标志,但我不知道如何使用该方法。我尝试过很多事情,但我很困惑在哪里该KeyEvent是从何而来,或者如果这是连正确的方法,我应该看。

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.

所以TL;博士:如何从当选择一个选项,关闭做我prevent选项菜单/子菜单

So tl;dr: How do I prevent options menus/submenus from closing when an option is selected?

推荐答案

就是我会使用标准的警告对话框类处理这个问题。在你的菜单处理程序,创建一个<一个href="http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setMultiChoiceItems"相对=nofollow> AlertDialog 和您选择的数组传递给生成器。

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.

您应该注意的是该方法 AlertDialog.Builder.setMultiChoiceItems(CharSequence的[]项,布尔[] checkedItems,DialogInterface.OnMultiChoiceClickListener监听器)

The method you should pay attention to is AlertDialog.Builder.setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)

传递一个数组此方法,并把你的子菜单中选择code在ClickListener。

Pass an array to this method and put your submenu selection code in the ClickListener.

这篇关于Android的辨认子菜单选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆