Reputation: 13349
I am writing an Android App where I need to display drop down list with an Image on Lefthand side rather that RadioButton in normal Spinner Control. I wanted to customize the spinner control. What are the steps to be followed in customizing Spinner in Android.
Can any one provide me sample code in sorting out this issue?
I will be waiting for valuable reply.
Thanks in Advance,
Upvotes: 0
Views: 1980
Reputation: 3233
The spinner popup items are fully customizable. Extend ArrayAdapter<T> and override the getDropDownView method. This method is called for each item. T type here is whatever types you give your adapter.
/** Expands the view and setup with the view for each item in spinner popup **/
@Override
public View getDropDownView(int position, View view, ViewGroup parent) {
T choice = getItem(position);
if (view == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// expand your list item here
view = vi.inflate(R.layout.mylistitem, null);
}
if(choice != null) {
// get whatever items are in your view
TextView text = (TextView) view.findViewById(R.id.text);
ImageView left = (ImageView) view.findViewById(R.id.leftImage);
// do whatever you want with your item view
}
return(view);
}
Override getView of the adapter to set the view of the main spinner control. You can have one call the other to have both the selection and popup have the same look.
Upvotes: 3