How to detect a click on searchView?
I have tried using setOnClickListener, setOnSearchClickListener, setOnFocusChangedListener, but to no avail.
The problem seems to be only click on textbox. If I click anywhere outside of textbox onClickListener triggers, but not if click inside the textbox.
The problem that I am trying to solve is that I need to close a if user clicks anywhere. But I dont know how to handle the SearchView.
I have managed to find a way to solve my problem. It's a bit hackish, but it works. You have to get the editText from searchView and set OnClickListener to it
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) searchView.findViewById(id);
editText.setOnClickListener(listener);
Try this:
searchView = (SearchView)findViewById(R.id.searchView);
searchView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setIconified(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