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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:30:51+00:00 2026-06-18T06:30:51+00:00

In my action bar I have 2 menu items: <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android>

  • 0

In my action bar I have 2 menu items:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/refresh"
          android:title="Refresh"
          android:icon="@drawable/refresh"
          android:showAsAction="ifRoom" >
    </item>
    <item android:id="@+id/back"
          android:title="Back"
          android:icon="@drawable/back"
          android:showAsAction="ifRoom" >
    </item>
</menu>

I’m trying to turn “invisible” my menu item “Refresh”, when I call the function refreshinvisible(), the Refresh item goes away, but now the action bar shows two “back” items… Why? (I’m using SherlockActionBar)

My refreshinvisible() function:

public void refreshinvisible(){
        MenuItem item = menu.findItem(R.id.refresh);
        item.setVisible(false);
}  

Anyone know how to proceed?

  • 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-18T06:30:53+00:00Added an answer on June 18, 2026 at 6:30 am

    There is a method called onPrepareOptionsMenu() which is called every time right before the menu is shown, i.e. before onCreateOptionsMenu() is called. You can use the activity’s invalidateOptionsMenu() method to trigger a redraw of the options menu.
    Hence, you can easily re-create your menu taking into account certain conditions.

    Here’s some code. Define two booleans as fields of your class, for example:

    private boolean showRefresh;
    private boolean showBack;
    

    Override the onPrepareOptionsMenu() method and set the menu item’s visbility depending on the respective boolean:

    @Override
    public boolean onPrepareOptionsMenu( Menu menu ) {
    
        super.onPrepareOptionsMenu( menu );
    
        menu.findItem( R.id.refresh ).setVisible( showRefresh );
        menu.findItem( R.id.back ).setVisible( showBack );
    
        return true;
    }
    

    No every time you want to change the visibility of a certain menu item, set the respective boolean accordingly and call the invalidateOptionsMenu() method.

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

Sidebar

Related Questions

I have actionbar menuitems cancel and save. menu.xml <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android >
So I have a few questions about implementing the Android action bar. Up to
I'm developing a simple Android application that would have an action bar on the
I have a menu item as part of my action bar menu, and I
I am working with the Android 3.0. I have in the action bar 3
Here is the dev guide related to the subject http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems So we have in
I have a refresh menu item in the action bar and my main layout
I have a main menu with an action bar. On create, I run a
my app have action bar on top of windows. Where are some buttons. Buttons
We have a file manager-like application where we use the action bar home button

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.