Android SearchView.OnQueryTextListener OnQueryTextSubmit not fired on empty query string

android, searchview

Solution

It is not a bug, the source code deliberately checks against null and empty values:

private void onSubmitQuery() {
    CharSequence query = mQueryTextView.getText();
    if (query != null && TextUtils.getTrimmedLength(query) > 0) {

However you should be able to use the OnQueryTextChange callback to clear your ListView's filterables when the user clears the search EditText.

Problem

I am using Android 4.1.2. I have a `SearchView` widget on an `ActionBar`. Documentation on `SearchView.OnQueryTextListener` from the android developer site states that `onQueryTextSubmit` is fired/Called when the user submits the query. This could be due to a keypress on the keyboard or due to pressing a submit button." This does not happen if the search query is empty. I need this to fire on an empty query to clear the search filter of a ListView. Is this a bug or am I doing something wrong?

Original source

Related problems