0

我已经编写了创建 Android 菜单的代码,但是按钮在按下时不执行操作。我似乎无法弄清楚问题所在。

   @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.option_menu, menu);
    return true;
}

public boolean onOptionsItemsSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.scan:
        //Launch DeviceListActivity to see devices and scan
        Intent serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
        System.out.println("Scan Pressed!");
        return true;
    case R.id.discoverable:
        //ensure device is discoverable
        ensureDiscoverable();
        System.out.println("Discoverable Pressed!");
        return true;            
    }
    return super.onOptionsItemSelected(item);
}

我得到这个 logcat 错误:

12-28 10:19:05.769:W/KeyCharacterMap(1876):加载 keycharmap 文件“/system/usr/keychars/qtouch-obp-ts.kcm.bin”时出错。hw.keyboards.131072.devname='qtouch-obp-ts' 12-28 10:19:05.769: W/KeyCharacterMap(1876): 无法打开 keycharmap 文件 12-28 10:19:05.769: W/KeyCharacterMap( 1876):使用默认键盘映射:/system/usr/keychars/qwerty.kcm.bin

4

1 回答 1

2

你有一个错字。该方法的名称是onOptionsItemSelected(),不是onOptionsItemsSelected()。你的方法永远不会被调用。

于 2012-12-28T10:52:21.680 回答