Im using an action bar and adding a searchView to it. I have implemented the searchView.onCLoseListener but this does not seem to be getting invoked. Any suggestions ?
My code looks something like this :
SearchView searchView = new SearchView(getContext());
searchView.setOnCloseListener(new OnCloseListener() {
  public boolean onClose() {
    searchView.setVisibility(SearchView.GONE);
    // Do Something
    return true;
  }
});
I ran into same problem on android 4.1.1. Looks like it is a known bug: https://code.google.com/p/android/issues/detail?id=25758
Anyway, as a workaround i used state change listener (when SearchView is detached from action bar, it is also closed obviously).
view.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
    @Override
    public void onViewDetachedFromWindow(View arg0) {
        // search was detached/closed
    }
    @Override
    public void onViewAttachedToWindow(View arg0) {
        // search was opened
    }
});
Above code worked well in my case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With