Skip to content

Instantly share code, notes, and snippets.

@mderazon
Created September 21, 2013 21:20
Show Gist options
  • Save mderazon/6654314 to your computer and use it in GitHub Desktop.
Save mderazon/6654314 to your computer and use it in GitHub Desktop.
adapter for autocomplete search box
// adapter for the search dropdown auto suggest
ArrayAdapter<JSONObject> searchAdapter = new ArrayAdapter<JSONObject>(this, android.R.id.text1) {
private Filter filter;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = this.getLayoutInflater().inflate(R.layout.search_item, parent, false);
}
TextView venueName = (TextView) convertView
.findViewById(R.id.search_item_venue_name);
TextView venueAddress = (TextView) convertView
.findViewById(R.id.search_item_venue_address);
final JSONObject venue = this.getItem(position);
convertView.setTag(venue);
try {
CharSequence name = highlightText(venue.getString("name"));
CharSequence address = highlightText(venue.getString("address"));
venueName.setText(name);
venueAddress.setText(address);
} catch (JSONException e) {
Log.i(Consts.TAG, e.getMessage());
}
return convertView;
}
@Override
public Filter getFilter() {
if (filter == null) {
filter = new VenueFilter();
}
return filter;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment