How to filter Recyclerview with SearchView on multiple parameters

岁酱吖の 提交于 2019-12-13 19:07:55

问题


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?


回答1:


Just add the city name verification here:

    if (product.contains(query) || city.contains(query)) {
        filteredModelList.add(model);
    }


来源:https://stackoverflow.com/questions/35678641/how-to-filter-recyclerview-with-searchview-on-multiple-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!