Skip to content

Instantly share code, notes, and snippets.

@sreereddymenon
Last active August 29, 2015 14:16
Show Gist options
  • Save sreereddymenon/e00cc77c91bf770b1d07 to your computer and use it in GitHub Desktop.
Save sreereddymenon/e00cc77c91bf770b1d07 to your computer and use it in GitHub Desktop.
// in the performFiltering method which runs on a background thread:
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
ArrayList<String> queryResults;
if (constraint != null || constraint.length() == 0) {
queryResults = autocomplete(constraint);
} else {
queryResults = new ArrayList<String>(); // empty list/no suggestions showing ig there's no constraint
}
filterResults.values = queryResults;
filterResults.count = queryResults.size();
}
private List<String> autocomplete(String input) {
// don't use the here the resultList List on which the adapter is based!
// some custom code to get items from http connection
ArrayList<String> queryResults = new ArrayList<String>(); // new list
queryResults.add("Some String");
return queryResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
resultList = (ArrayList<String>)results.values;
if (results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment