Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event when searchview expands from iconified view

What event(s) I should listen to determine when user clicks on iconified SearchView. I want to remove some items (ActionBar navigation tabs, if that is important) from action bar to make more space in portrait orientation.

I've tried OnClickListener, OnFocusChangeListener, OnTouchListener and other events but neither gets triggered by SearchView expansion.

like image 770
Juozas Kontvainis Avatar asked Nov 05 '11 11:11

Juozas Kontvainis


1 Answers

Since API Level 14 you have a dedicated listener: http://developer.android.com/guide/topics/ui/actionbar.html

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.options, menu);
        MenuItem menuItem = menu.findItem(R.id.actionItem);
        ...

    menuItem.setOnActionExpandListener(new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            return true;       // Return true to collapse action view
        }
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // Do something when expanded
            return true;      // Return true to expand action view
        }
    });
}
like image 92
VeV Avatar answered Nov 06 '22 06:11

VeV