Skip to content

Instantly share code, notes, and snippets.

@kmdupr33
Created June 15, 2015 11:07
Show Gist options
  • Save kmdupr33/7d70bdc59cea4e35c8f3 to your computer and use it in GitHub Desktop.
Save kmdupr33/7d70bdc59cea4e35c8f3 to your computer and use it in GitHub Desktop.
private class ArrayFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence prefix) {
FilterResults results = new FilterResults();
if (prefix == null || prefix.length() == 0) {
ArrayList<T> list;
synchronized (mLock) {
list = new ArrayList<T>(mOriginalValues);
}
results.values = list;
results.count = list.size();
} else {
//...
final ArrayList<T> newValues = new ArrayList<T>();
for (int i = 0; i < count; i++) {
final T value = values.get(i);
final String valueText = value.toString().toLowerCase();
// First match against the whole, non-splitted value
if (valueText.startsWith(prefixString)) {
newValues.add(value);
} else {
//...
}
}
}
return results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment