2

The DropDownViewResource is applied on a Spinner but not on a AutoCompleteTextView.

This works :

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this.getActivity(), R.layout.spinner_item, usersHistory);
arrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

Spinner userSpinner = dialogLayout.findViewById(R.id.country);
userSpinner.setAdapter(ArrayAdapter);

This does NOT work :

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this.getActivity(), R.layout.spinner_item, usersHistory);
arrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

AutoCompleteTextView userAutoCompleteTextView = dialogLayout.findViewById(R.id.country);
userAutoCompleteTextView.setAdapter(ArrayAdapter);

Does anyone know how I can set a "custom dropdown layout" to the an AutoCompleteTextView?

Greelings
  • 4,964
  • 7
  • 34
  • 70
  • try this https://stackoverflow.com/questions/16782288/autocompletetextview-with-custom-adapter-and-filter – Akshay Sep 04 '18 at 11:20
  • @akshay Thank you, but why on Android should we always reinvent the wheel... It's a simple drop down list with an unique TextView. Can't we do it without using a custom adapter? – Greelings Sep 04 '18 at 11:34

1 Answers1

1

For AutoCompleteTextView's, it's the dropdown view resourceId that you pass into the ArrayAdapter's constructor.

So instead of:

new ArrayAdapter<>(this.getActivity(), R.layout.spinner_item, usersHistory);

It should be:

new ArrayAdapter<>(this.getActivity(), R.layout.spinner_dropdown_item, usersHistory);

(Although I use android.R.layout.simple_spinner_dropdown_item.)

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253