自定义autocompletetextview适配器不过滤和输入奇怪的字符串

时间:2013-10-09 10:15:21

标签: java android android-arrayadapter autocompletetextview

我为autocompletetextview制作了一个自定义适配器,但是当你选择一个项目时,它不会过滤文本并输入奇怪的字符串。喜欢这个字符串:

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;
}

}

0 个答案:

没有答案