选择结果后,AutoCompleteTextView返回模型

时间:2016-06-27 05:14:36

标签: java android autocompletetextview

我在搜索专业和学校时使用autocompleteTextview。在我的自动填充textbox中,它会返回实际的可搜索查询字符串,例如

major = Computer Science 
schools = Harvard University

但点击所选项目后,它会返回类似

的模型

这是我学校适配器中的过滤器代码

 @Override
public Filter getFilter() {
    Filter filter = new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults filterResults = new FilterResults();
            if(constraint != null){
                List<MTSSchool> filterValue = new ArrayList<MTSSchool>();

                for(int x = 0; x < _filtteredSchoolList.size(); x++){
                    if(_filtteredSchoolList.get(x).getSchool_name().contains(constraint)){
                        MTSSchool university = new MTSSchool(_filtteredSchoolList.get(x).getSchool_name(),_filtteredSchoolList.get(x).getSchoolId());
                        filterValue.add(university);
                    }
                }

                filterResults.values = filterValue;
                filterResults.count = filterValue.size();
            }
            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            if(results != null && results.count > 0){
                _filtteredSchoolList = (List<MTSSchool>)results.values;
                notifyDataSetChanged();
            }else {
                notifyDataSetInvalidated();
            }
        }
    };
    return filter;
}

  protected void publishResults(CharSequence constraint, FilterResults results) {
            if(results != null && results.count > 0){
                _filtteredSchoolList = (List<MTSSchool>)results.values;
                notifyDataSetChanged();
            }else {
                notifyDataSetInvalidated();
            }
        }

enter image description here

在自动填充中选择选项后,这是输出

我注意到我的3个autocompleteTextview它没有重置搜索结果,但它限制了其他自动完成任何建议吗?

1 个答案:

答案 0 :(得分:1)

对于MTSSchool类,实现一个返回学校名称的toString()方法