DropDownViewResource 应用于微调器,但不应用于 AutoCompleteTextView。
这有效:
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);
这不起作用:
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);
有谁知道如何将"自定义下拉布局"设置为自动完成文本视图?
对于AutoCompleteTextView,它是您传递给 ArrayAdapter 构造函数的下拉视图 resourceId。
所以代替:
new ArrayAdapter<>(this.getActivity(), R.layout.spinner_item, usersHistory);
它应该是:
new ArrayAdapter<>(this.getActivity(), R.layout.spinner_dropdown_item, usersHistory);
(虽然我用android.R.layout.simple_spinner_dropdown_item
。