我需要从SearchView获取文本并将其与我的活动的ListView中的字符串进行比较,如果SearchView中的单词在我的ListView中,则显示Toast.我怎么做?这是我的SearchView工作代码:
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) { return false; } @Override public boolean onQueryTextChange(String newText) { adapter.getFilter().filter(newText); } return false; } });
starkshang.. 44
测试SearchView
,使用searchView.getQuery()
.
测试SearchView
,使用searchView.getQuery()
.
试试这段代码:
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; } });