开发者

"No keyboard for id 0"?

开发者 https://www.devze.com 2023-01-19 20:20 出处:网络
I am new in Android app. development, now I have encountered a strange problem with the Menu 开发者_JAVA技巧button. Here is the thing:

I am new in Android app. development, now I have encountered a strange problem with the Menu 开发者_JAVA技巧button. Here is the thing:

I have two activities, "ActivityOne" and "ActivityTwo", where "ActivityTwo" is the child Activity of "ActivityOne". In both activity, I have defined the menu button options like following:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuItem insertMenuItem = menu.add(0, INSERT_ID, 0, R.string.menu_insert);
    insertMenuItem.setIcon(R.drawable.ic_menu_add);

    MenuItem settingMenuItem = menu.add(0, SETTING_ID, 0, R.string.menu_setting);
    settingMenuItem.setIcon(R.drawable.ic_menu_settings);

    MenuItem aboutMenuItem = menu.add(0, ABOUT_ID, 0, R.string.menu_about);
    aboutMenuItem.setIcon(R.drawable.ic_menu_about);

    logPrinter.println("creating menu options...");

    return true;
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch(item.getItemId()) {
        case INSERT_ID:
            doInsert();
            return true;
        case SETTING_ID:
         return true;
        case ABOUT_ID:
         showAbout();
         return true;
    }

    return super.onMenuItemSelected(featureId, item);
}

In "ActivityOne", when I click the physical Menu button, there is no menu options pop up from screen bottom, when I checked the LogCat console, there are two warning messages, which are "No keyboard for id 0" and "Using default keyMap:/system/usr/keychars/qwerty.kcm.bin" .

BUT, in "ActivityTwo", the menu button works fine, it shows me those menu options I defined.

Why the menu button does not work in "ActivityOne" ?? What does the warning msg mean???


The "no keyboard for id 0" doesn't mean anything.

Now, have you defined onCreateOptionsMenu in both activities? If not, do it.

Also, use onOptionsItemSelected instead of onMenuItemSelected.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号