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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:47:06+00:00 2026-05-23T20:47:06+00:00

How do I change the options menu at run-time in android 2.3.3? I have

  • 0

How do I change the options menu at run-time in android 2.3.3? I have two xml menus and need to switch menu type at run-time.

I would like to destroy or update the menu and when the user then presses the menu button, onCreateOptions menu is then called again selecting the appropriate xml menu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    if(OPTIONS_TYPE == 0) // Photo option
        getMenuInflater().inflate(R.menu.photomenu, menu);
    else // Photo + delete option
        getMenuInflater().inflate(R.menu.photodeletemenu, menu);

    return super.onCreateOptionsMenu(menu);
}
  • 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-23T20:47:07+00:00Added an answer on May 23, 2026 at 8:47 pm

    The onCreateOptionsMenu only gets called once. There may be a hack that lets you remove an options menu, but the standard way to modify it after that call is as follows from the android docs, note that it says “must”

    Changing menu items at runtime

    Once the activity is created, the onCreateOptionsMenu() method is called only once, as described above. The system keeps and re-uses the Menu you define in this method until your activity is destroyed. If you want to change the Options Menu any time after it’s first created, you must override the onPrepareOptionsMenu() method.

    Documentation is at Creating Menus

    Now having said that you can do this, just not sure if it’s supported. This is just my own test code where I swap the menus each time, you will need to add your own logic

    @Override
    public boolean onPrepareOptionsMenu (Menu menu) {
    
        menu.clear();
    
        if (OPTIONS_TYPE == 0) {
            OPTIONS_TYPE = 1; 
            getMenuInflater().inflate(R.menu.secondmenu, menu);
    
        }
        else { // Photo + delete option {
            OPTIONS_TYPE = 0;
            getMenuInflater().inflate(R.menu.firstmenu, menu);
        }
    
        return super.onPrepareOptionsMenu(menu);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to change Visual Studio Auto formatting options? Like VS by
I have a .change() function set for a dropdown menu with an ID of
How would I change the initial templates created by Xcode when creating a new
How can I change the title of the command prompt window every time I
The problem is that the following method gets called one time when the Menu
I have a snippet to create a 'Like' button for our news site: <iframe
Change Data Capture is a new feature in SQL Server 2008. From MSDN: Change
Is it possible to change the width of a scroll bar on a form.
Lately I had to change some code on older systems where not all of
How can I change default Generate Method Stub behavior in Visaul Studio to generate

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.