Search code examples
androidactionbarsherlock

SearchView: can't capture the close event


I use the ActionBarShellock 4.2. I think the OnCloseListener() would be called when I click the closebutton but no response when i did it.

mSearchView.setOnCloseListener(new OnCloseListener() {
        @Override
        public boolean onClose() {
            Toast.makeText(mContext, "OnCloseListener", 1000).show();
            return false;
        }
    });

I've tried to call the getChildAt(index) to get the closebutton. Then I think it's unsafe cause the SearchView is not my own code. So, how can I capture the close event? Did I do in the wrong way?
thanks in advance.

enter image description here


Solution

  • Just get your menuItem, then setOnActionExpandListener. Then override unimplents methods.

    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
    
        return true;
    }
    
    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
    
       //do something on close
       // you must return true
        return true;
    }
    

    Hack done good luck