views:

53

answers:

1

I have a selection for some items using a spinner widget. At the moment the spinner will load a simple Textview and show the name of the item.
It is possible to define an own view to show inside the spinner row? I would suspect it being similar to a custom List row.

I simply want to show an individual icon left from the spinner text for each item in the list.

+3  A: 

Yes, you can do that - as you may know, Spinner is a type of AdapterView, which means that you can adapt your own data to show in such View.

The approach is pretty similar to the one with ListView. Excerpt from ApiDemos:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, INTERPOLATORS);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);

You can define your own layout and pass it to the SpinnerAdapter subclass that you use.

Dimitar Dimitrov