4

我想覆盖一个 performfiltering 以便我可以过滤多个选择,

我已经搜索了谷歌,请参阅: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();
             }

     }
}
}

我正在考虑将字符序列设为一个数组并在 for 循环中与 performfilter 一起使用它,但后来我得到了一个关于未实现代码的错误。

4

0 回答 0