使用标题和子项自动完成textview

时间:2017-12-06 09:29:37

标签: android autocompletetextview

我正在努力实现this

我使用了自定义数组适配器

$ awk -F '[ ,]' 'NR==1{p=$6;next} $6!=p+1{print "Mismatched line no:"NR} {p=$6}' file
Mismatched line no:5

我正在获取对象列表,并根据对象类型操作视图。 由于自动完成视图的自定义数组适配器需要覆盖<template> <v-layout row wrap > <v-flex xs12> <v-form v-model="valid" ref="form"> <v-layout row wrap> <v-flex xs3 v-for="option in selectOptions" :key="option.text"> <v-checkbox :label="option.text" v-model="selected" :value="option.value"></v-checkbox> </v-flex> <v-flex xs3> <v-btn small class="primary">save</v-btn> </v-flex> </v-layout> </v-form> <p>selected options : {{selected}}</p> </v-flex> </v-layout> </template> <script> export default{ data(){ return { valid: false, selected:[], selectOptions:[ {text: 'Apples', value: 'apple'}, {text: 'Oranges', value: 'orange'}, {text: 'Grapes', value: 'grape'} ] } }, } } </script> 方法才能知道我们的过滤逻辑,所以我已经实现了我的逻辑,但当它到达public class SearchItemAdapter extends ArrayAdapter<Object> { List<Object> mObjects; private final List<Object> mDepartmentsAll; public SearchItemAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<Object> objects) { super(context, resource, objects); this.mObjects=new ArrayList<>(objects); this.mDepartmentsAll=new ArrayList<>(objects); } @Override public int getViewTypeCount() { return 2; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { int viewType= getItemViewType(position); switch (viewType){ case 0: HearderViewHolder viewHolder=null; if (convertView==null){ convertView = LayoutInflater.from(getContext()).inflate(R.layout.search_drop_down_header, parent, false); viewHolder = new HearderViewHolder(convertView); SearchableHeaders searchableHeaders= (SearchableHeaders) mObjects.get(position); viewHolder.mHeader.setText(searchableHeaders.getSearchableHeader()); convertView.setTag(viewHolder); } break; case 1: StringViewHolder stringViewHolder = null; if (convertView==null){ convertView = LayoutInflater.from(getContext()).inflate(R.layout.search_drop_down, parent, false); stringViewHolder = new StringViewHolder(convertView); SearchableStrings searchableStrings = (SearchableStrings) mObjects.get(position); searchableStrings.getSearchableString(); stringViewHolder.mString.setText(searchableStrings.getSearchableString()); convertView.setTag(stringViewHolder); } break; } return convertView; } @Override public int getItemViewType(int position) { if (mObjects.get(position) instanceof SearchableHeaders){ return 0; } else { return 1; } } class HearderViewHolder { TextView mHeader; public HearderViewHolder(View view) { mHeader = (TextView) view.findViewById(R.id.txtSearchHeader); } } @NonNull @Override public Filter getFilter() { return new Filter() { @Override public String convertResultToString(Object resultValue) { if (resultValue instanceof SearchableHeaders){ return ((SearchableHeaders) resultValue).getSearchableHeader(); } else { return ((SearchableStrings) resultValue).getSearchableString(); } } @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults filterResults = new FilterResults(); List<String> departmentsSuggestion = new ArrayList<>(); if (constraint != null) { for (Object department : mDepartmentsAll) { if (department instanceof SearchableStrings){ departmentsSuggestion.add(((SearchableStrings) department).getSearchableString()); } else if (department instanceof SearchableHeaders){ departmentsSuggestion.add(((SearchableHeaders) department).getSearchableHeader()); } } filterResults.values = departmentsSuggestion; filterResults.count = departmentsSuggestion.size(); } return filterResults; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { mObjects.clear(); if (results != null && results.count > 0) { // avoids unchecked cast warning when using mDepartments.addAll((ArrayList<Department>) results.values); for (Object object : (List<?>) results.values) { if (object instanceof SearchableStrings){ mObjects.add(((SearchableStrings) object).getSearchableString()); } else if (object instanceof SearchableHeaders){ mObjects.add(((SearchableHeaders) object).getSearchableHeader()); } } notifyDataSetChanged(); } else if (constraint == null) { // no filter, add entire original list back in for (Object department : mDepartmentsAll) { if (department instanceof SearchableStrings){ mObjects.add(((SearchableStrings) department).getSearchableString()); } else if (department instanceof SearchableHeaders){ mObjects.add(((SearchableHeaders) department).getSearchableHeader()); } } notifyDataSetInvalidated(); } } }; } class StringViewHolder { TextView mString; public StringViewHolder(View view) { mString = (TextView)view.findViewById(R.id.txtSearchString); } } } 时它会返回一个对象的arraylist,In getFilter()函数我已经返回了仅包含字符串的过滤结果,为什么我会得到arraylist? 有没有其他方式来获得这样的建议清单?

0 个答案:

没有答案