执行setShortcut('0','a');的效果应该是 点击0或者a都会激发MenuItem所对应的onOptionsItemSelected()吧?       但是为什么我每次执行的效果都是,点击a会执行onOptionsItemSelected(),而点击0则没有反应,这是为什么?

解决方案 »

  1.   

    你的setShortcut是在哪儿用到的啊?
      

  2.   

    在onCreateOptionsMenu函数中。
      

  3.   

    首先弄清楚setshortcut是干嘛用的:
    设置快捷键和浮动说明文字    调用函数item的成员函数setShortcut(numericChar, alphaChar)
    还有它的两个参数的意义...
      

  4.   

    Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case. 
    See Menu for the menu types that support shortcuts.
    Parameters
    numericChar The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard. 
    alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. 
    ReturnsThis Item so additional setters can be called.
     
    以上是Google提供的Reference。我的理解,两个参数都是快捷键
      

  5.   

    google提供的完整说明:
    public abstract MenuItemsetShortcut(char numericChar, char alphaChar) 
    Since: API Level 1
    Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case. 
    See Menu for the menu types that support shortcuts.
    Parameters
    numericChar The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard. 
    alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys. 
    ReturnsThis Item so additional setters can be called. 也查了网上的资料,的确两个参数都是快捷键。你可以使用setShortcut方法给菜单项指定快捷键。每一次调用setShortcut需要两个快捷键,一个是数字键,另一个可以是全键盘中的键。任何键不区分大小写。
    下面的代码片段给出了如何为两种模式设定快捷键:
    // Add a shortcut to this menu item, ‘0’ if using the numeric keypad// or ‘b’ if using the full keyboard.menuItem.setShortcut(‘0’, ‘b’);但是为什么只有字母快捷键起效,就不知道了。
      

  6.   

    终于知道原因了。
    setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘。
    数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的。其实我怀疑有这种键盘的手机能装Android么?
    因为我的键盘不是12键盘,所以数字快捷键是无法工作的。只有字母快捷键能够起效。
      

  7.   

    Parameters
    numericChar  The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard. 
    alphaChar  The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.