Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SearchView on ActionBar, detect click on Search

In my application, like many other, there is a common search widget (http://developer.android.com/guide/topics/search/search-dialog.html#UsingSearchWidget).

I would change fragment (and pass to it the term searched) only when the search button on the keyboard is pressed.

I've tried with

searchView.setOnSearchClickListener(new OnClickListener() { 
@Override public void onClick(View v) { 
} });

but it is triggered when you press the button ON THE ACTION BAR, that uncollapse the search input, and not when the keybord button search is clicked.

Do you know how is possible?

like image 534
M4rk Avatar asked Jun 20 '14 18:06

M4rk


1 Answers

You can use this tо detect search key press in action bar search:

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String s) {
                [You actions here]
                return false;
            }
}
like image 131
Timur Gilfanov Avatar answered Oct 19 '22 05:10

Timur Gilfanov