为什么我的选项菜单显示不正确的设置菜单项? [英] Why is my options menu not showing the settings menu item correctly?

查看:201
本文介绍了为什么我的选项菜单显示不正确的设置菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这是从 https://developers.facebook.com/docs/android/美味/验证

这是我的code(相同从教程)的选项菜单部分

This is my code (identical from the tutorial) for the options menu part

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // only add the menu when the selection fragment is showing
        if (fragments[SELECTION].isVisible()) {
            if (menu.size() == 0) {
                settings = menu.add(R.string.settings);
            }
            return true;
        } else {
            menu.clear();
            settings = null;
        }
        return false;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        if (item.equals(settings)) {
            showFragment(SETTINGS, true);
            return true;
        }
        return false;
    }

发生了什么是这个工程的大部分时间,但我发现一个测试用例我不能调试。当你注销,菜单项仍然显示,你必须点击它,使之消失。(它不应该出现在所有)。这不是在一开始给我巨大的关注,但我发现,当您再次登录您单击菜单项,使之消失后,选项菜单不会出现在所有。

whats happening is this works most of the time but I found a test case I couldn't debug. When you logout, the menu item still shows and you have to click it to make it disappear.(it shouldn't appear at all). This wasn't a huge concern to me at the beginning but I found that when you logged in again after you clicked the menu item to make it disappear, the options menu doesn't appear at all.

推荐答案

我想我找到了问题,我把它留给别人。从<一个href=\"http://stackoverflow.com/questions/7659354/when-and-how-often-on$p$ppareoptionsmenu-method-is-called-for-actionbar\">When如何经常在prepareOptionsMenu()方法被调用的ActionBar?,我说:在Android 3.0及更高版本,您必须调用invalidateOptionsMenu()当您要更新的菜单,因为菜单始终是开放的,系统会然后prepareOptionsMenu(打电话),因此您可以更新菜单项。
当我退出,甚至认为没有实际的菜单项,在菜单仍然是开放的。然而,当我点击菜单时,它是空的,它搞砸了,以至于当我登录,显示是行不通的。我不明白的部分呢。我希望有人能详细的一部分时发生了什么。

I think I found the problem, I leave it up for others. From When and how often onPrepareOptionsMenu() method is called for ActionBar? ,I got that "On Android 3.0 and higher, you must call invalidateOptionsMenu() when you want to update the menu, because the menu is always open. The system will then call onPrepareOptionsMenu() so you can update the menu items." When I logged out, even thought there were no actual menu items, the menu was still open. However when I clicked the menu when it was empty, it messed it up so that when I logged in, show wouldn't work. I don't understand that part yet. I was hoping someone can elaborate what happened during that part

这篇关于为什么我的选项菜单显示不正确的设置菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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