Search code examples
androidandroid-searchmanagerandroid-search

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?


Solution

  • 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;
                }
    }