问题
I try to filter in Listview where the adapter is ListAdapter, I couldn't find getFilter() , Is there any work around? Below is my code.
// Adding menuItems to ListView
final ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[]{"songTitle"}, new int[]{
R.id.songTitle});
setListAdapter(adapter);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//adapter.getFilter
return false;
}
});
回答1:
I find myself, It's simple.
final SimpleAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[]{"songTitle"}, new int[]{
R.id.songTitle});
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;
}
});
来源:https://stackoverflow.com/questions/35417010/how-to-use-getfilter-form-listadapter