I have an AutoCompleteTextView with a custom adapter. What I want is when I type a text in the searchbox, I want to set text color only to the word in suggestion that contains the text and not the whole suggestion. How do I do it. Below is my custom adapter.
public class SearchAutoComplectAdapter extends ArrayAdapter<TagBo> {
Context context;
LayoutInflater inflate;
private VenueFilter filter;
public SearchAutoComplectAdapter(Context context, int resource) {
super(context, android.R.layout.simple_list_item_1);
this.context = context;
inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflate.inflate(R.layout.search_item, parent, false);
}
TextView venueName = (TextView) convertView
.findViewById(R.id.search_item_venue_name);
venueName.setTextColor(context.getResources().getColor(R.color.cyan));
TextView venueAddress = (TextView) convertView
.findViewById(R.id.search_item_venue_address);
TagBo recordBo=getItem(position);
// TODO add shared With Me check
if(recordBo.getTagTypeId() == 3){
venueName.setText(recordBo.getName());
venueAddress.setVisibility(View.GONE);
}else{
venueName.setText(recordBo.getName());
venueAddress.setText(recordBo.getSuggestText());
venueAddress.setVisibility(View.VISIBLE);
}
return convertView;
}
@Override
public Filter getFilter() {
if (filter == null) {
filter = new VenueFilter();
}
return filter;
}
private class VenueFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
if(constraint!=null ){
List<TagBo> matchingTags = TagDao.getMatchingTags(constraint.toString());
StringBuilder text = new StringBuilder();
for (TagBo tag : matchingTags) {
text.append(tag.getSuggestText() + "\n");
}
result.values = matchingTags;
result.count = matchingTags.size();
}else{
result.count = 0;
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
// we clear the adapter and then pupulate it with the new results
clear();
if (results.count > 0) {
for (TagBo o : (ArrayList<TagBo>) results.values) {
add(o);
}
notifyDataSetChanged();
}
}
}
}