我必须写一个@BindingAdapter
接受 Spinner 和EnumSet<T>
:
@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
项目的文本太长而无法放入一行,则文本不会被换行而是像这样被切断:
谁能告诉我应该在哪里以及我应该改变什么来换行?