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

  • SEARCH
  • Home
  • 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 8399057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:11:56+00:00 2026-06-09T21:11:56+00:00

I am trying to display a menu item named share by clicking the menu

  • 0

I am trying to display a menu item named “share” by clicking the menu button.
now i need to create a submenu item for this share menu item.
The sub menu item should be visible when the share menu item is clicked alternatively (when clicked first time becomes visible next time invisible and so on.).
I found few solutions which are displaying the sub menuitems but those are being displayed along with the menu item.

This is my code for creating menus

public boolean onCreateOptionsMenu(Menu m) {

    m.add(1,1,0,"one").setIcon(R.drawable.icon);
    m.add(1,2,0,"two").setIcon(R.drawable.icon);
    m.add(1,3,0,"three").setIcon(R.drawable.icon);
    m.add(1,4,0,"four").setIcon(R.drawable.icon);
    m.getItem(0).setVisible(false);
    m.getItem(1).setVisible(false);
    return true;
}

and my onPrepareOptionsMenu()

public boolean onPrepareOptionsMenu(Menu m) {
    if(isvisible)
    {
    isvisible = false;
     m.getItem(0).setVisible(true);

    m.getItem(1).setVisible(true);


}
else{
    isvisible = true;
    m.getItem(0).setVisible(false);

    m.getItem(1).setVisible(false);

}


    return super.onPrepareOptionsMenu(m);

}

I need the remaining two items to be shown when i click on the menu item rather than on the menu button.
Can anyone suggest me please

  • 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-06-09T21:11:57+00:00Added an answer on June 9, 2026 at 9:11 pm

    override the below method:

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        return super.onPrepareOptionsMenu(menu);
    }
    

    The above method is called every time before the menu is shown.

    Here you can maintain a bool and hide the submenu depending upon the condition of your check.
    

    EDIT:

    By default set bool to false and on false show the menu and set the bool to true and on next call check this bool and if it is true, set it false and make the menu invisible.use this line to make the menu visible or invisible:

    menu.getItem(index).getSubMenu().getItem(index).setVisible(true);
    Store the bool in sharedpreference.

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

Sidebar

Related Questions

I am trying to display the options menu when a list item is checked
Im trying to create a menu item so when a user clicks on the
I am trying to display a 'products' menu item in my top menu then
I'm trying to make changing background image by menu item. It's works now but
I am trying to create a sub navigation. Right now I have two subnav.
I am trying to create an additional menu item for the Project and Solutions
I'm trying to create a menu, in which the last menu item (with different
I am trying to display my popover menu whenever the user clicks on a
I'm trying to display the items in the menu-items variable using the for-macro: (defrecord
I'm trying to display standard file/directory context menu in WinForms application - I'd like

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.