开发者

Edit Options menu item content/settings in android

I need to edit the value of a MenuItem in my Android application. But the problem is that i don't want the item edited inside OnCreateOptionMenu, but i want it edited outside MenuHandling routines.

I tried to use that code but it doesn't work:

Menu myMenu = (Menu) findViewById(R.id.optionsmenu);
menuItem = myMenu.findItem(R.id.timer);
menuItem.setEnable(false);

But it doesn't work the myMenu variable value is null (i added in an id attribute in the Menu xml tag). I also tried something like that:

Menu myMenu = (Menu) findViewById(R.menu.options);
menuItem = myMenu.findI开发者_StackOverflow中文版tem(R.id.timer);
menuItem.setEnable(false);

Same problem. I also tried:

MenuItem myItem = (MenuItem) findViewById(R.id.timer);
myItem.setEnabled(false);

Same problem myItem is null. Then how i can modify the MenuItem? I know how to id inside the On*OptionsMenu methods. I nedd to do it outside these method.

Thanks in advance for any help/reply.


override the onPrepareOptionsMenu() in your activity.

Refer this doc:

http://developer.android.com/guide/topics/ui/menus.html#ChangingTheMenu

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜