Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoSearchTextView dropdown flickers when data changes

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!

like image 715
serenskye Avatar asked Jul 01 '26 08:07

serenskye


1 Answers

Okay, It turns out the answer was quite simple, sometimes the best way it to just check the source code :)

AutoSearchTextView has a method public void onFilterComplete(int count) which in turn calls private void updateDropDownForFilter(int count), if the count is zero the dropdown will be hidden.

You must set count on your FilterResults object returned from your Filter protected FilterResults performFiltering(CharSequence constraint) method.

filterResults.count = result.getHistory().size() + result.getQueryResults().size();

solved the issue.

like image 61
serenskye Avatar answered Jul 02 '26 23:07

serenskye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!