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?
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.
I've an easier work around: use onQueryTextChange, but only render if it's empty.
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
renderList(true);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (searchView.getQuery().length() == 0) {
renderList(true);
}
return false;
}
});
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