I have an AutoSearchTextView in the actionbar. When I filter the data the dropdown hides and then shows very quickly. I really would prefer the effect on the play store, where you filter results, the dropdown is always visible but the content in the dropdown changes.
This is my filter code in my Adapter, run history query, gets the history and sets the list items.
@Override
public Filter getFilter() {
if (filter == null) {
filter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
ResortFilterResult result = new ResortFilterResult();
String substr = constraint.toString().toLowerCase();
if (constraint != null) {
if (constraint.length() > 0) {
result.setHistory(runHistoryQuery(substr));
}
if (constraint.length() >= 3) {
LCResort[] resorts = searchResortWithQuery(substr);
result.setQueryResults(Arrays.asList(resorts));
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = result;
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
ResortFilterResult result = (ResortFilterResult)results.values;
history = result.getHistory();
resorts = result.getQueryResults();
notifyDataSetChanged();
}
};
}
return filter;
}
EDIT: I am one step closer - It turns out dismiss dropdown on the TextView is being called every time I type a new character!
please don't reinvent the wheel, use existing Filter instead of creating your own one
and the easiest is to use FilterQueryProvider together with e.g. SimpleCursorAdapter or when extending CursorAdapter just override runQueryOnBackgroundThread(), using that you will avoid errors like you have now
EDIT:
in your case if you dont need a custom Adapter use a SimpleCursorAdapter with custom FilterQueryProvider overriding runQuery() you can return all the data you need (see my answer here how i query wikipedia: How to dynamically add suggestions to autocompletetextview with preserving character status), if you REALLY need a custom Adapter extend CursorAdapter and do exactly the same in runQueryOnBackgroundThread() what you did in FilterQueryProvider.runQuery(), also when your data comes from more then one source use a MergeCursor but its perfectly ok to just use one MatrixCursor