简体   繁体   English

android AutoCompleteTextView似乎忽略了自定义ArrayAdapter的Filter

[英]android AutoCompleteTextView seems to ignore the Filter of the custom ArrayAdapter

All I want to do is displaying a CheckBox at each result of the AutoCompleteTextView's results (which are strings). 我要做的就是在AutoCompleteTextView结果的每个结果(是字符串)上显示一个CheckBox。

I wrote an custom Array Adapter which implements Filterable. 我写了一个实现Filterable的自定义数组适配器。 I added a simple Filter wich gets called (I checked that) and returns the expected results. 我添加了一个简单的过滤器,该过滤器被调用(我检查了)并返回了预期的结果。 However the displayed results are completely different ones. 但是,显示的结果完全不同。

Here is my Filter-Code: 这是我的过滤器代码:

private class MyFilter extends Filter
    {
        @Override
        protected FilterResults performFiltering(CharSequence constraint)
        {
            FilterResults results = new FilterResults();
            if ((constraint == null) || (constraint.length() == 0))
            {
                synchronized (mLock)
                {
                    ArrayList<String> list = new ArrayList<String>();
                    results.values = list;
                    results.count = list.size();
                }
            }
            else
            {
                String constr = constraint.toString().toLowerCase();
                final ArrayList<String> newItems = new ArrayList<String>();
                for (String temp : items)
                {
                    if (temp.toLowerCase().startsWith((constr)))
                    {
                        newItems.add(temp);
                    }
                }
                results.values = newItems;
                results.count = newItems.size();
            }
            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint,
                FilterResults results)
        {
            if (results.count > 0)
            {
                notifyDataSetChanged();
            }
            else
            {
                notifyDataSetInvalidated();
            }
        }
    }

Do I miss something? 我想念什么吗? Thank you! 谢谢!

我忘记将结果设置为适配器的新项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM