Shubham
Shubham

Reputation: 1442

Spinner with image and text

I want my spinner to look like this enter image description here

Only the topmost header should have image and text. Remaining drop down should have text only. Can anyone help me in making this.

I have tried this..

I my xml file

 <Spinner android:id="@+id/spinner1"
 android:layout_width="200dp"
 android:layout_height="50dp"
 android:layout_alignParentLeft="true"
 android:layout_below="@id/view" 
android:layout_marginLeft="35dp"
 android:layout_marginTop="20dp"
 android:background="@drawable/grey_btn"
 android:popupBackground="@drawable/drop_down_background"
 android:spinnerMode="dropdown" />

and then

ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(mContext, R.drawable.spinner_text,R.id.customtextview,arr1); adapter1.setDropDownViewResource(R.drawable.drop_down); s1.setAdapter(adapter1);

Upvotes: 1

Views: 1369

Answers (1)

Mikael Svensson
Mikael Svensson

Reputation: 720

You should have both a getView and getDropDownView in the adapter. In that way you could specify different looks on the selected item and the rest of the list.

in getView:

textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.VISIBLE);

in getDropDownView:

textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.INVISIBLE);

Upvotes: 2

Related Questions