0

I have made a custom adapter for a autocompletetextview, but it's not filtering on the text and inputting weird strings when you select a item. Like this string:

listadapters.LocatieRowItem@BSE433q4e30

I have made this adapter so the first item of the autocompletetextview could have a image and a different color then the rest.

Here is my custom adapter:

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

}

Wesley Egbertsen
  • 720
  • 1
  • 8
  • 25
  • You should set the text like `holder.txtTitle.setText(items.get(position).getTitle()`. – GrIsHu Oct 09 '13 at 10:34
  • It diden't work when I select a item it still puts that weird string in the text field. – Wesley Egbertsen Oct 09 '13 at 11:16
  • You try to implement methods like `@Override public int getCount() { return items.size(); } @Override public Object getItem(int position) { return items.get(position); } @Override public long getItemId(int position) { return position; }` – GrIsHu Oct 09 '13 at 11:20
  • The problem issen't by setText right? because that is setting the text of the textview in the item from the autocomplete(that is going fine), my problem is that when I select a item that weird string will be set in the textfield from the autocompletetextview. – Wesley Egbertsen Oct 09 '13 at 11:25
  • 1
    In that case post the code of Itemclick . – GrIsHu Oct 09 '13 at 11:30
  • O god I'm stupid I forgot to create a OnItemClickListerner I did this and it works: `@Override public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub LocatieRowItem item = (LocatieRowItem) arg0.getItemAtPosition(arg2); txtAutoVan.setText(item.getTitle()); }` – Wesley Egbertsen Oct 09 '13 at 11:37
  • Now to get the filtering working... – Wesley Egbertsen Oct 09 '13 at 11:38

0 Answers0