Android菜单按钮无响应

时间:2012-12-28 09:50:04

标签: android android-intent android-activity

我已经编写了创建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

1 个答案:

答案 0 :(得分:2)

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