我想覆盖一个执行过滤,所以我可以过滤多个选择,
我有搜索谷歌搜索,请参阅:stack1
但我不知道如何使用答案。
那么some1可以帮我解决这个问题吗?
在下面提供过滤类(在数组适配器类(在它下面)):
public void resetData()
{
wines=winesOriginal;
}
public Filter getFilter() {
if (wineFilter == null){
wineFilter = new WineFilter();
}
return wineFilter;
}
private class WineFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence chars) {
FilterResults result = new FilterResults();
if (chars != null && chars.length() > 0) {
ArrayList<Wine> filter = new ArrayList<Wine>();
String filterString = chars.toString().toLowerCase();
for (Wine object : wines) {
object.getBiologic();
// the filtering itself:
if (object.getName().toLowerCase().contains(chars.toString().toLowerCase())
||object.getColor().toLowerCase().contains(chars.toString().toLowerCase())
||object.getCountry().toLowerCase().contains(chars.toString().toLowerCase())
||object.getTaste().toLowerCase().contains(chars.toString().toLowerCase())
||String.valueOf(object.getYear()).contains(chars.toString())
||Boolean.valueOf(object.getBiologic().toString().equals(chars.toString().toLowerCase()))
||Boolean.valueOf(object.getSparkling().toString().equals(chars.toString().toLowerCase())))
filter.add(object);
}
result.count = filter.size();
result.values = filter;
}
else {
// add all objects
synchronized (this) {
result.values = winesOriginal;
result.count = winesOriginal.size();
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
// Now we have to inform the adapter about the new list filtered
if (results.count == 0)
notifyDataSetInvalidated();
else {
wines = (List<Wine>) results.values;
notifyDataSetChanged();
}
}
}
}
我正在考虑将charsequence作为一个数组,并在带有performfilter的for循环中使用它,但后来我得到了一个关于未实现的代码的错误。