Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:36:43+00:00 2026-05-23T16:36:43+00:00

I have a menu created through: @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(Email); return

  • 0

I have a menu created through:

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Email");

    return super.onCreateOptionsMenu(menu);
  }

But I can’t remember how to set a onclicklistener so when its selected I can run my email function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:36:44+00:00Added an answer on May 23, 2026 at 4:36 pm

    Override onOptionsItemSelected(MenuItem item). So it would be like

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 0:
                // do whatever
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    

    EDIT:

    Since this has gotten so many points, I should note that it is very good to add ID’s to the menu options. A good way to ensure they are always unique is to define them in an ids.xml resource that is put in the res/values folder.

    ids.xml

    <resources>
        <item name="menu_action1" type="id"/>
        <item name="menu_action2" type="id"/>
        <item name="menu_action3" type="id"/>
    </resources>
    

    Then when you override the onCreateOptionsMenu(Menu menu) method, you can use the IDs like so:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      super.onCreateOptionsMenu(menu);
    
      menu.add(Menu.NONE, R.id.menu_action1, Menu.NONE, R.string.menu_action1);
      menu.add(Menu.NONE, R.id.menu_action2, Menu.NONE, R.string.menu_action1);
    
      return true;
    }
    

    Override onOptionsItemSelected(MenuItem item).

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_action1:
                // do whatever
                return true;
            case R.id.menu_action2:
                // do whatever
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    

    The reason you do this is the Activity would override this with menu options, but Fragments can also add their own menu items. Using the ids.xml ensures the IDs are unique no matter which order they are placed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Drupal Menu which I created through the interface. I wish to
Have created a ATL COM project through which I am inserting Menu Items to
I have a menu with an animation going on, but I want to disable
I have a asp:menu object which I set up to use a SiteMapDataSource but
I have created a menu using a treeview to launch forms when the user
I have created a menu using CSS and Javascript. When I click on a
I have created a Menu named MY Command and I mentioned M as mnemonic
I have created branches for one project, but now I have a need to
I have a menu running off of a sitemap which one of the SiteMapNode
I have a menu control inside of an updatepanel. When I hover over a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.