为AutoCompleteTextView和Spinner使用相同的自定义适配器

时间:2016-03-28 08:29:53

标签: android android-arrayadapter android-spinner autocompletetextview

所以我为SpinnerAutoCompleteTextView使用了一个适配器,扩展了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

功能齐全,两者都很好。但是从用户界面来看,一团糟......为什么会这样?

0 个答案:

没有答案