如何在适配器上应用多个过滤器? [英] How to apply multiple Filters on an Adapter?

查看:39
本文介绍了如何在适配器上应用多个过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 listView 和一个搜索字段,它调用我的适配器的 getFilter().filter(keyword) 函数.它工作得很好,但我想添加一个其他过滤器来搜索我的 listViews 对象的不同标签.

I got a listView with and a search field that calls my Adapter's getFilter().filter(keyword) func. It is working very nice, but i would like to add an other filter that searches in different tags of my listViews's objects.

所以我的适配器需要两个过滤器,最好的解决方案是什么?

So i need two filters for my Adapter, whats the best solution for this?

谢谢,

推荐答案

我想你自己实现了过滤器.由于您无法获得两个过滤器,因此您可以在过滤器中有一个字段来定义应应用的过滤类型(您可以在过滤器中使用多个过滤器).

I suppose that you implemented the filter yourself. As you cant get two filters you could have a field in the filter that defines what kind of filtering should by applied ( you could use multiple filters in your filter).

在使用过滤器之前,将过滤器的字段设置为您想要的值.

Set you field of the filter to the value you want before using the filter.

或者:

使用关键字选择要应用的过滤器.在关键字的开头添加一些定义要应用的过滤器的字符.使用 String.beginsWith() 您可以检查必须应用哪种类型的过滤.这必须在过滤器本身中完成.getFilter.filter(keyword) 的调用者必须知道必须在字符串前面添加哪些字符.

Use the keyword to choose the filter to apply. Add on the beginning of the keyword some characters which define the filter to apply. With String.beginsWith() you can check which type of filtering has to by applied. This has to be done in the Filter itself. The caller of the getFilter.filter(keyword) has to know what characters have to by added in front of the string.

这篇关于如何在适配器上应用多个过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆