在我來說,我剛使用標準佈局微調的項目,並覆蓋一點點一個ArrayAdapter。
private class PaymentTypeArrayAdapter extends ArrayAdapter<PaymentType> {
public PaymentTypeArrayAdapter(Context context) {
super(context, android.R.layout.simple_spinner_item);
addAll(PaymentType.getPaymentTypes());
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getView(position, convertView, parent);
PaymentType paymentType = getItem(position);
label.setText(paymentType.getStringResourceId());
label.setCompoundDrawablesWithIntrinsicBounds(0, 0, paymentType.
getImageResourceId(), 0);
return label;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
PaymentType paymentType = getItem(position);
label.setText(paymentType.getStringResourceId());
label.setCompoundDrawablesWithIntrinsicBounds(0, 0, paymentType.
getImageResourceId(), 0);
return label;
}
}
然後爲您的微調適配器:
mPaymentTypeArrayAdapter = new PaymentTypeArrayAdapter(getContext());
setAdapter(mPaymentTypeArrayAdapter);
在這種方法的關鍵是使用setCompoundDrawablesWithIntrinsicBounds的標籤要更改微調的背景
做什麼? –
http://stackoverflow.com/questions/3609231/how-is-it-possible-to-create-a-spinner-with-images-instead-of-text –