所以我为Spinner
和AutoCompleteTextView
使用了一个适配器,扩展了ArrayAdapter<Object>
。对于与视图相关的方法,我只覆盖getView
。
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView tv = (TextView) view;
//I do something with TextView here, but won't affect the problem
return view;
}
现在,两者都声明如下:
adapterSpinner = new CustomAdapter(
this, R.layout.custom_layout_item, objects);
adapterService.setDropDownViewResource(
R.layout.custom_dropdown_layout);
spinner.setAdapter(adapterSpinner);
adapterAutoComplete = new CustomAdapter(
this, R.layout.custom_layout_item, objects);
adapterAutoComplete.setDropDownViewResource(
R.layout.custom_dropdown_layout);
autoComplete.setAdapter(adapterAutoComplete);
结果令我困惑:
AutoCompleteTextView
将custom_layout_item
应用于其下拉列表视图,而是将其在xml中的元素style
应用于其TextView / EditText布局。它忽略了我设置的custom_dropdown_layout
。
微调
正确应用所有这些,使用custom_layout_item
的TextView视图,以及使用custom_dropdown_layout
的下拉视图。虽然它忽略了我在xml中给它的style
。
功能齐全,两者都很好。但是从用户界面来看,一团糟......为什么会这样?