How to filter Recyclerview with SearchView on multiple parameters

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?


只需在这里添加城市名称验证:

    if (product.contains(query) || city.contains(query)) {
        filteredModelList.add(model);
    }
链接地址: http://www.djcxy.com/p/92966.html

上一篇: 查询提交后,SearchView不会响应点击次数

下一篇: 如何在多个参数上使用SearchView过滤RecyclerView