在SearchView中添加多个字段搜索

时间:2018-07-15 11:26:23

标签: android android-recyclerview searchview

我有$wp_rewrite->rules,并且可以使用以下代码在SearchView中进行搜索:

RecyclerView

如您所见,此代码仅在private List<Question> filter(List<Question> models, String query) { query = query.toLowerCase(); final List<Question> filteredModelList = new ArrayList<>(); for (Question model : models) { final String text = model.getTitle().toLowerCase(); if (text.contains(query)) { filteredModelList.add(model); } } return filteredModelList; } 上进行搜索,因此,有什么方法可以在2个提交的model.getTitle()model.getTitle()中进行搜索?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试以下代码,

private List<Question> filter(List<Question> models, String query) {
    query = query.toLowerCase();
    final List<Question> filteredModelList = new ArrayList<>();
    for (Question model : models) {
        final String textTitle = model.getTitle().toLowerCase();
        final String textContent = model.getTitle().toLowerCase();
        if (textTitle.contains(query) || textContent.contains(query)) {
            filteredModelList.add(model);
        }
    }
    return filteredModelList;
}