I need to get a text from SearchView and compare it to strings in my activity\'s ListView and show a Toast if the word in a SearchView is in my ListView. How do I do that? H
To get text of SearchView
, use searchView.getQuery()
.
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;
}
});