I.G. Pascual I.G. Pascual - 2 days ago 4
Android Question

How do I submit a SearchView programatically?

I'm trying to submit a

SearchView
that I have in my
Toolbar
from a click of a
Button
that I created in my layout.

This is the relevant code in my search activity:

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
....
@Override
public boolean onQueryTextSubmit(String query) {
makeQuery(query);
return true;
}
});

searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// searchView submit??
}
});


Is there any method like
searchView.onSubmit()
searchView.onQuerySubmit();
?

Any clues?

Answer

You can do this

searchView.setQuery(searchView.getQuery(), true);
Comments