blackdog
blackdog

Reputation: 2107

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

Upvotes: 2

Views: 1393

Answers (1)

An-droid
An-droid

Reputation: 6485

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

Upvotes: 3

Related Questions