Instantly share code, notes, and snippets.

What would you like to do?
package com.manishkpr.autotextviewexample;
import java.util.ArrayList;
import java.util.List;
import android.widget.ArrayAdapter;
import android.widget.Filter;
public class SuggestionAdapter extends ArrayAdapter<String> {
protected static final String TAG = "SuggestionAdapter";
private List<String> suggestions;
public SuggestionAdapter(Activity context, String nameFilter) {
super(context, android.R.layout.simple_dropdown_item_1line);
suggestions = new ArrayList<String>();
public int getCount() {
return suggestions.size();
public String getItem(int index) {
return suggestions.get(index);
public Filter getFilter() {
Filter myFilter = new Filter() {
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
JsonParse jp=new JsonParse();
if (constraint != null) {
// A class that queries a web API, parses the data and
// returns an ArrayList<GoEuroGetSet>
List<SuggestGetSet> new_suggestions =jp.getParseJsonWCF(constraint.toString());
for (int i=0;i<new_suggestions.size();i++) {
// Now assign the values and count to the FilterResults
// object
filterResults.values = suggestions;
filterResults.count = suggestions.size();
return filterResults;
protected void publishResults(CharSequence contraint,
FilterResults results) {
if (results != null && results.count > 0) {
} else {
return myFilter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment