In my app, implement a SearchView. I managed to make it work perfectly but I had several doubts when I saw it work:
I need a mechanism for when there are no results I show a textview that there is not ... so I did the following
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
serviceAdapter.getFilter().filter(newText);
if (serviceAdapter.getCount() <1) {
findViewById(R.id.tvNoResult).setVisibility(View.VISIBLE);
gridView.setVisibility(View.GONE);
}else{
findViewById(R.id.tvNoResult).setVisibility(View.GONE);
gridView.setVisibility(View.VISIBLE);
}
return true;
}
});
I added a hidden TextView in my xml and in the java I made a condition that said if the adapter was less than 1 it would hide the GridView and show the TextView, everything worked as expected but the problem is that when you press the back button or the one to close, the SearchView I am left the TextView visible and then it hinders me the operation:
This is how it looks like later:
My question is: is there a method to work with the back button and close the SearchView? What can I do to prevent this from happening?