如何基于AutoCompleteTextView中的多个值执行搜索

时间:2014-06-02 08:11:23

标签: android android-arrayadapter autocompletetextview simpleadapter

我使用AutoCompleteTextView搜索City。我正在使用Array Adapter来绑定AutoCompleteTextView。现在我想在AutoCompleteTextView上输入城市或邮政编码,并希望基于此列出城市列表。我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以在ArrayAdapter中使用名称过滤器:

        @Override
        public Filter getFilter() {
            return nameFilter;
        }

        Filter cityFilter = new Filter() {
            public String convertResultToString(Object resultValue) {
                String str = ((YourObject) (resultValue)).getName();
                return str;
            }

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
            //Your code for find CIty by name or zip 
        }

           @Override
                protected void publishResults(CharSequence constraint,
                        FilterResults results) {
                //You can now update youArrayList and after you need call notifyDataSetChanged
                        notifyDataSetChanged();
                    }
                }
            };