0

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?

2
  • When you say "buttons", do you mean buttons on the device or buttons in your activity?
    – Malachi
    Commented Jul 29, 2011 at 18:23
  • Inside the activity. Thanks for clarifying. Commented Jul 29, 2011 at 18:26

1 Answer 1

1

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!

2
  • 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?
    – Brian
    Commented Jul 29, 2011 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.