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 8666181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:39:51+00:00 2026-06-12T17:39:51+00:00

In short, here’s my question: Can option menus (shown in the actionbar) be modified

  • 0

In short, here’s my question:

Can option menus (shown in the actionbar) be modified programatically on android 3.0+?

I have a wizard-style activity in which I use a ViewFlipper to switch between views, or steps.

The steps are: 1 -> 2 -> 3. Only the second screen (2) has a menu item, while the others don’t. I have tried hanging on to the Menu reference (source) and either removing/adding items or just hiding/showing them.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.mMenu = menu;
    
    getMenuInflater().inflate(R.menu.my_menu, menu);
    mMenu.getItem(0).setVisible(false);
    
    return super.onCreateOptionsMenu(menu);
}

Switch to the second screen ->

public void showNext(View v) {
    if (mVFlipper.getDisplayedChild() < (mVFlipper.getChildCount() - 1)) {
        mVFlipper.showNext();
        if (mVFlipper.getDisplayedChild() == 1) {
            setTitle("Second screen");
            mMenu.getItem(0).setVisible(true);
        }
    }
}

This works fine on 2.2, but fails miserably on 4.1. Starting off with a visible MenuItem and hiding it later works. Starting off with an invisible menu item and showing it later –

  • 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-12T17:39:53+00:00Added an answer on June 12, 2026 at 5:39 pm

    There is a bug in Android’s MenuItem setVisible that causes problems when turning items back to visible.

    In your onCreateOptionsMenu(), add a check to see if the displayed page needs the Menu, if it does, add the MenuItem. Then, call invalidateOptionsMenu() whenever the page changes. That will rebuild the Menu.

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

Sidebar

Related Questions

I have a SVNSERVE server set up to host multiple repositories. Short question here
Here is the short version. I have a Bonus Activity that has 25 image
First question here: it is a very short yet fundamental thing in Java that
Short question - how do you define your view models? Here are some of
Okay, here's my short question: I know that === and !== operators will compare
Quick question here about short-circuiting statements in C#. With an if statement like this:
Bit of a long explanation below, with a hopefully accurate short question summary here:
I have two classes in short here they are: public final class ServerMain {
I am dealing with a short deadline here, so I will ask this question
Keep the question here short and sweet. I'm Getting a 500 error when I

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.