问题描述:

I am using an ArrayAdapter with a custom object and the autocomplete text view is printing my custom object to string when i want it to display a field. I thought I could override my filter method like this

@Override

public CharSequence convertResultToString(Object resultValue) {

Tag result = (Tag) resultValue;

return result.getName();

}

This is called but seems to have no effect on the displayed result4

edit filter class

Filter filter = new Filter() {

@Override

protected FilterResults performFiltering(CharSequence constraint) {

FilterResults filterResults = new FilterResults();

resultList.clear();

if (constraint != null) {

Iterable<String> iterable = st.keysWithPrefix(constraint.toString());

Iterator<String> iterator = iterable.iterator();

while (iterator.hasNext()) {

String keys = iterator.next();

resultList.add(st.get(keys));

}

// Retrieve the autocomplete results.

filterResults.values = resultList;

filterResults.count = resultList.size();

}

return filterResults;

}

@Override

public CharSequence convertResultToString(Object resultValue) {

Tag result = (Tag) resultValue;

return result.getName();

}

@Override

protected void publishResults(CharSequence constraint, FilterResults results) {

if (results != null && results.count > 0) {

notifyDataSetChanged();

} else {

notifyDataSetInvalidated();

}

}

};

相关阅读:
Top