Search code examples
androidsubmitsearchview

How do I submit a SearchView programmatically?


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();?


Solution

  • You can do this

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