Added toolbar search widget:

<item android:id="@+id/action_search" android:icon="@android:drawable/ic_menu_search" app:showAsAction="always" app:actionViewClass="android.support.v7.widget.SearchView" android:title="Search"/> 

How to hang something like TextChangedListener on it?

UPD

 public boolean onPrepareMenuOptions(Menu menu) { MenuItem item = menu.findItem(R.id.action_search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(item); mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { sferaAdapter.getFilter().filter(newText); return false; } }); return true; } 

Is everything right here? Does not work.

    1 answer 1

    1. In onPrepareOptionsMenu, find your SearchView as a MenuItem in the menu by its ID.
    2. Get a link to SearchView itself using the getActionView method.
    3. Now you can hang on it TextChangedListener

    But in XML it can not be done

    • Please expand the second point - Beginner
    • @ Newbie, Something like this: SearchView searchView = (SearchView) menuItem.getActionView() - Yurii SPb
    • It did. Something in searchview methods I can’t find TextChangedListener - Novice
    • setOnQueryTextListener - is it? - Newcomer
    • one
      @ Newbie, your method is not originally the same. You need onPrepareOptionsMenu and not onPrepareMenuOptions as you wrote. You have confused the words Metsami - Yuriyi SPb