Code example for SearchView

Methods: setOnQueryTextListener, setOnSuggestionListener

0
 
  @Override 
  public void configureSearchWidget(Activity activity, final MenuItem menuItem) {
    super.configureSearchWidget(activity, menuItem);
    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
      @Override 
      public boolean onQueryTextSubmit(String query) {
        menuItem.collapseActionView();
        return false; 
      } 
      @Override 
      public boolean onQueryTextChange(String newText) {
        return false; 
      } 
    }); 
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override 
      public boolean onSuggestionSelect(int position) {
        return false; 
      } 
      @Override