How to get a text from SearchView?
try this code :
MenuItem ourSearchItem = menu.findItem(R.id.menu_item_search);
SearchView sv = (SearchView) ourSearchItem.getActionView();
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Toast.makeText(getContext(), query, Toast.LENGTH_SHORT).show();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
}
return false;
}
});
To get text of SearchView
, use searchView.getQuery()
.