Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView.OnCloseListener does not get invoked

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;
  }
});
like image 886
lokoko Avatar asked Dec 17 '12 19:12

lokoko


1 Answers

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.

like image 84
Dario Avatar answered Sep 20 '22 08:09

Dario