Created
September 21, 2013 21:20
-
-
Save mderazon/6654314 to your computer and use it in GitHub Desktop.
adapter for autocomplete search box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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