0
我必須寫一個@BindingAdapter
它接受微調和EnumSet<T>
:Android的數據綁定微調適配器
@BindingAdapter(value = {"android:entries"})
public static <T extends Enum<T> & ITextable> void bindSpinnerData(Spinner spinner, EnumSet<T> entries) {
spinner.setAdapter(new ArrayAdapter<T>(spinner.getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<>(entries)) {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView textView = (TextView) v.findViewById(android.R.id.text1);
ITextable item = getItem(position);
textView.setText(item.getText());
return v;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = super.getDropDownView(position, convertView, parent);
TextView textView = (TextView) v.findViewById(android.R.id.text1);
ITextable item = getItem(position);
textView.setText(item.getText());
return v;
}
});
}
我有一個問題,因爲如果一個Spinner
項目的文本是太長,無法成單行線,在文本不包裝,而切斷這樣的:
誰能告訴我在哪裏和什麼我應該改變包裝的文本?
我嘗試setSinglLine on textView,但它不起作用。我將spinnerMode設置爲對話框,它工作。謝謝 – forfiter9
最後,我用第二個選項覆蓋getDopDownView – forfiter9