How do I submit a SearchView programmatically?
Asked Answered
C

2

6

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

Cardiovascular answered 1/12, 2016 at 14:23 Comment(0)
L
14

You can do this

searchView.setQuery(searchView.getQuery(), true);
Lanita answered 1/12, 2016 at 14:38 Comment(0)
A
2

Well, try to use SearchView#setQuery(CharSequence query, boolean submit). This will submit your request if true. If false only query data will be changed.

Hope, it helps

Aureole answered 1/12, 2016 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.