I would like to have two options menus in Android that are triggered using buttons inside the activity. Is this possible? If so, how would I go about doing so?
1 Answer
I'm not sure if there's a direct way of doing this, but there is kind of a work around. You could create the method that launches the menu the regular way, by declaring public boolean onCreateOptionsMenu(Menu menu)
and/or public boolean onPrepareOptionsMenu(Menu menu)
but have two different "modes". From your button, you can programmatically open the options menu by simply calling openOptionsMenu()
. Just before you open the menu, just set the "mode" to whatever the button's menu should be in. I hope you understand what I mean, let me know if you need clarifying!
-
I understand exactly what you mean. Very useful, just one question, is there a method of adding a "title" to the options menu so that you can distinguish between the menus? Commented Jul 29, 2011 at 19:24
-
From my experience, and I'm sure yours as well, I don't think it's possible. I've never seen an options menu with a title. Perhaps you could use a toast to tell the user?– BrianCommented Jul 29, 2011 at 19:35