4

I have an AutoCompleteTextView in my application, but there is a lot more behind every item in the DropDownMenu than what is displayed.

I have my own ArrayAdapter for the AutoCompleteTextView, and when the user starts typing anything the autocompleteTextView starts to reduce the drop down list. This is what I want to change. Every time the user types a new letter, I´m making a new search from the database and would like to show all of those in the drop down menu that pops up, i.e I dont want the autocompleteTextView to reduce the list due to what the user is typing.

So, my question is, is there a way to block an autocompleteTextView from reducing the results, or is it easier to just do an edit text view with my own drop down menu?

Thanks.

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
Malin
  • 655
  • 4
  • 10
  • 20
  • I think EditText option is the best way to implement this functionality compare to autoCompleteTextView. – Mr.Sandy Jul 09 '13 at 12:43

1 Answers1

5

Finally, I found a solution that worked perfectly. Just want to share it since I spend a lot of time to get it work.

The AutoCompleteTextView does not have any methods to set no filter, or any way to use a custom filer.

As I wrote I have a custom ArrayAdapter to the AutoCompleteTextView. So what I did was in the ArrayAdapter class, override the function getFilter.

And give the cred to the people posting the answer here.

@Override
  public Filter getFilter() {
    return new KNoFilter();
}

private class KNoFilter extends Filter {

    @Override
    protected FilterResults performFiltering(CharSequence arg0) {
        FilterResults result = new FilterResults();
            result.values = searchResults;
            result.count = searchResults.size(); 
        return result;
    }

    @Override
    protected void publishResults(CharSequence arg0, FilterResults arg1) {
        notifyDataSetChanged();
    }
}
Community
  • 1
  • 1
Malin
  • 655
  • 4
  • 10
  • 20