我正在尝试ArrayAdapter
为我的AutoCompleteTextView
喜欢设置一个自定义
public class AutoCompleteContactArrayAdapter extends
ArrayAdapter<Map<String, String>> implements Filterable {
private Context mContext;
private List<Map<String, String>> mContactList;
public AutoCompleteContactArrayAdapter(Context context,
List<Map<String, String>> objects) {
super(context, R.layout.auto_contact_list, objects);
mContext = context;
mContactList = objects;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.auto_contact_list, parent,
false);
TextView nameView = (TextView) rowView.findViewById(R.id.ccontName);
TextView phoneView = (TextView) rowView.findViewById(R.id.ccontNo);
TextView typeView = (TextView) rowView.findViewById(R.id.ccontType);
Map<String, String> contactMap = mContactList.get(position);
nameView.setText(contactMap.get("name"));
phoneView.setText(contactMap.get("phone"));
typeView.setText(contactMap.get("type"));
return rowView;
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
if (results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
ArrayList<String> result = new ArrayList<String>();
result.add("test");
result.add("another");
result.add("last");
FilterResults r = new FilterResults();
r.values = result;
r.count = result.size();
return r;
}
};
}
}
在调试中,应用程序同时输入了filter
方法publishResults()
,performFiltering()
但是显示的结果集不是我的测试array
[test,another,last] 而是它只显示忽略我的过滤器的所有结果。