背景色だけにしたい場合は、この例のように使用できます。
public class CustomSpinnerAdapter<T extends BaseEntity> extends ArrayAdapter implements SpinnerAdapter {
private final List<T> objects; // android.graphics.Color list
public CustomSpinnerAdapter(Context context, List<T> objects) {
super(context, R.layout.yourLayout, objects);
this.context = context;
this.objects = objects;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
super.getDropDownView(position, convertView, parent);
View rowView = convertView;
if (rowView == null) {
// Get a new instance of the row layout view
LayoutInflater inflater = this.activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.yourLayout, null);
rowView.setBackgroundColor(objects.get(position));
} else {
rowView.setBackgroundColor(objects.get(position));
}
return rowView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
// Get a new instance of the row layout view
LayoutInflater inflater = this.activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.yourLayout, null);
rowView.setBackgroundColor(objects.get(position));
} else {
rowView.setBackgroundColor(objects.get(position));
}
return rowView;
}
}