Reputation: 11
I have implemented the SearchView example given here.
How to filter a RecyclerView with a SearchView
....to filter and list company names based on the parameter "Product name".
In my project, I want to extend this to further filter on the parameter on "city name"
The below is the code for the onQueryTextSubmit which filters on the parameter "productname".
@Override public boolean onQueryTextSubmit(String query) { return false; }
private List<ExampleModel> filter(List<ExampleModel> models, String query) {
query = query.toLowerCase();
final List<ExampleModel> filteredModelList = new ArrayList<>();
for (ExampleModel model : models) {
final String text = model.getText().toLowerCase();
final String city = model.getCity().toLowerCase();
final String product = model.getProduct().toLowerCase();
final String services = model.getServices().toLowerCase();
final String state = model.getState().toLowerCase();
final String zone = model.getZone().toLowerCase();
if (product.contains(query)) {
filteredModelList.add(model);
}
}
return filteredModelList;
}
How should I go forward from here?
Upvotes: 1
Views: 1206
Reputation: 6988
Just add the city name verification here:
if (product.contains(query) || city.contains(query)) {
filteredModelList.add(model);
}
Upvotes: 1