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

i need to be able to change the options menu (the one that is
I have the same standard options menu, but I want to change the background
I have a list of states in an option menu. I'd like to run
I have two frames - left frame contains menu options created using css and
I have an option menu in Android. Now it has got 5 options. When
On clicking a certain MenuItem in a Options Menu in Android, I need to
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
To change Proxy server I have to go to IE->Internet Options->LAN Settings and click
I have a userscript that has to change a whole list of options depending
I am a little bit stuck: I would like to change the max option

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.