I am trying to trigger an onCancel() when the user exit of the search dialog by pressing the left arrow button, but this never occurs. I tried register the cancel listener in the main activity OnCreate(), or in onViewCreated() ; also in the fragment using the search box. The code :
final SearchManager searchManager = (SearchManager)getSystemService(SEARCH_SERVICE);
searchManager.setOnCancelListener(
new SearchManager.OnCancelListener() {
@Override
public void onCancel() {
Log.e("cancel","--------------");
}
}
);
The Log.e line is never called. Thanks
In the SearchView guide says:
So if you want to handle dismissal that occurs after user has searched (search is executed) then you must handle it by implementing OnDismissListener.
If you want to handle cancellation that occurs when the searchview is closed without doing any search (search is not executed) then you handle it in an OnCancelListener.
You can handle the both as well.