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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:24:15+00:00 2026-06-15T14:24:15+00:00

I am using Actionbar Sherlock and and i have three buttons Search with a

  • 0

I am using Actionbar Sherlock and and i have three buttons

  1. Search with a SearchView
  2. Categories which opens a Dialog Fragment
  3. Sort which opens a hiddent drop down menu

When i click the Search Button the SearchView text expands. When the Search view has expanded i want to hide all the other icons from the action bar and it should return when i exit the expanded searchView mode.

public class MainActivity extends SherlockFragmentActivity implements
        SearchView.OnQueryTextListener {
    protected static CharSequence[] _categories = { "Amusement Park",
            "Bird Sanctuary", "Wild Life", "River", "Hill Station", "Temple" };

    protected static boolean[] _selections = new boolean[_categories.length];
    public SearchView mSearchView;
    private TextView mStatusView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        MenuItem categoryItem = menu.findItem(R.id.action_category);
        MenuItem sortItem = menu.findItem(R.id.action_sort);
        mSearchView = (SearchView) searchItem.getActionView();
        setupSearchView(searchItem, categoryItem, sortItem);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        /*
         * case R.id.action_go: Intent i = new Intent(MainActivity.this,
         * PlaceActivity.class); startActivity(i); break;
         */
        /*
         * case R.id.action_search: Toast.makeText(this, "Searh",
         * Toast.LENGTH_LONG).show(); break;
         */
        case R.id.action_category:
            showDialog();
            break;
        case R.id.action_sort_alpha_az:
            Toast.makeText(this, "Alpha AZ", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_alpha_za:
            Toast.makeText(this, "Alpha ZA", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_dist_nf:
            Toast.makeText(this, "Dist NF", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_dist_fn:
            Toast.makeText(this, "Dist FN", Toast.LENGTH_LONG).show();
            break;
        default:
            // return super.onOptionsItemSelected(item);
            break;
        }
        return true;
    }

    private void setupSearchView(MenuItem searchItem, MenuItem categoryItem,
            MenuItem sortItem) {
        mSearchView.setIconifiedByDefault(true);
        searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS
                | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    }

    public boolean onQueryTextChange(String newText) {
        Log.i("Nomad", "onQueryTextChange");
        return false;
    }

    public boolean onQueryTextSubmit(String query) {
        Log.i("Nomad", "onQueryTextSubmit");
        return false;
    }

    public boolean onClose() {
        Log.i("Nomad", "onClose");
        return false;
    }

    protected boolean isAlwaysExpanded() {
        return false;
    }


}
  • 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-15T14:24:16+00:00Added an answer on June 15, 2026 at 2:24 pm

    I’m doing the same as follows:

    private Menu mainMenu = null;
    
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);
    
        mainMenu = menu;
    
        MenuItem searchItem = menu.findItem(R.id.action_search);
        MenuItem categoryItem = menu.findItem(R.id.action_category);
        MenuItem sortItem = menu.findItem(R.id.action_sort);
        mSearchView = (SearchView) searchItem.getActionView();
        mSearchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) { 
                    //hide  action item
                    if (mainMenu != null)   
                        mainMenu.findItem(R.id.quick_actions).setVisible(false);
            }
        });
        mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {           
            @Override
            public boolean onClose() {
                //re-show the  action button 
                    if (mainMenu != null)
                        mainMenu.findItem(R.id.quick_actions).setVisible(true);
                return false;
            }
        });
        //setupSearchView(searchItem, categoryItem, sortItem);
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement Action Bar using ActionBar Sherlock. I have three Action
I am using IntelliJ Idea CE (which is incredible) and have included ActionBar Sherlock
I have app which has actionbar containing 1) up button which opens side bar
I am using the Sherlock ActionBar library and I have a SherlockFragmentActivity implementing ActionBar.TabListener
I have an ActionBar using ActionBar Sherlock where I need it to display overflow
I am new to using the Sherlock ActionBar and I have make it run
Using ActionBar Sherlock to implements tabs, I have a new TabsAdapter object declared and
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
Is it possible to customize layout of android.widget.SearchView (I'm using it in actionBar)? 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.