果冻豆不调用prepareOptionsMenu()打开菜单的时候第一次 [英] Jelly bean not calling onPrepareOptionsMenu() when opening the menu for the first time

查看:209
本文介绍了果冻豆不调用prepareOptionsMenu()打开菜单的时候第一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就重写prepareOptionsMenu隐藏和显示菜单项。当API级别16模拟器测试它;在$ P首次打开菜单时$ ppareOptionsMenu不叫。但是,当我重​​新打开菜单它的作品。现在的问题是只与第一使用。有了这个,你可以简单的测试;

I'm overriding onPrepareOptionsMenu to hide and show menu items. When testing it with the API level 16 emulator; onPrepareOptionsMenu is not called when opening the menu for the first time. But when i reopen the menu it works. The problem is only with the first usage. You can simple test it with this;

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Toast.makeText(this.getActivity(), "pre", Toast.LENGTH_SHORT).show();
    super.onPrepareOptionsMenu(menu);
}

任何想法?

推荐答案

上prepareOptionsMenu()每个用户打开的姜饼和下方的菜单时,被称为。从蜂巢了选项菜单,假设永远是开放的,当项目都在ActionBar present。

onPrepareOptionsMenu() is called each time the user opens the menu on Gingerbread and below. From Honeycomb up the Options Menu is assumed to always be open when items are present in the ActionBar.

如果你想在你的活动生命周期和上prepareOptionsMenu()您需要调用回调中更新选项菜单 invalidateOptionsMenu ()上prepareOptionsMenu()将被调用。

If you want to update the Options Menu during your activities lifecyle and within the onPrepareOptionsMenu() callback you need to call invalidateOptionsMenu() and the onPrepareOptionsMenu() will be called.

你能不执行code在 onCreateOptionsMenu()回调您第一次使用?这就是所谓的每个选项菜单被创建时,它是在第一次使用创建的。

Could you not implement the code for your first usage in the onCreateOptionsMenu() callback? It is called every time the Options Menu is created and it is created on first use.

这篇关于果冻豆不调用prepareOptionsMenu()打开菜单的时候第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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