Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 946
I.G. Pascual Avatar asked Dec 06 '22 16:12

I.G. Pascual


2 Answers

You can do this

searchView.setQuery(searchView.getQuery(), true);
like image 83
Niza Siwale Avatar answered Dec 28 '22 18:12

Niza Siwale


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

like image 25
Mody Avatar answered Dec 28 '22 18:12

Mody