我为自动完成文本视图制作了一个自定义适配器,但是当您选择一个项目时,它不会过滤文本并输入奇怪的字符串。像这个字符串:
listadapters.LocatieRowItem@BSE433q4e30
我已经制作了这个适配器,所以 autocompletetextview 的第一项可以有一个图像和不同的颜色,然后其他的。
这是我的自定义适配器:
public class LocatieAdapter extends ArrayAdapter<LocatieRowItem> {
Context context;
private List<LocatieRowItem> items;
public LocatieAdapter(Context context, int resourceId, List<LocatieRowItem> items) {
super(context, resourceId, items);
this.context = context;
this.items = items;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
TextView txtTitle;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LocatieRowItem rowItem = items.get(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.locatieitem, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.text1);
holder.imageView = (ImageView) convertView.findViewById(R.id.logo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(rowItem.getTitle().equals("huidige locatie")) {
if (holder.imageView.getVisibility() != View.VISIBLE) {
holder.imageView.setVisibility(View.VISIBLE);
holder.txtTitle.setTextColor(Color.parseColor("#33B5E5"));
holder.txtTitle.setPadding(40, 10, 5, 5);
}
} else {
holder.imageView.setVisibility(View.GONE);
holder.txtTitle.setTextColor(Color.parseColor("#333333"));
holder.txtTitle.setPadding(10, 10, 10, 10);
}
holder.txtTitle.setText(rowItem.getTitle());
//convertView.setBackgroundColor(position % 2 == 0 ? Color.WHITE : Color.parseColor("#F8F8F8"));
return convertView;
}
}