Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Change Spinner Dropdown view

Im My application I want the below type of Spinner Dropdown view .enter image description here For this type of spinner view. I wrote this code.

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.spinner, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner_obj.setAdapter(adapter);

I got this from http://developer.android.com/guide/topics/ui/controls/spinner.html But what I got is, enter image description here

Please provide me the best way to do this....

like image 741
Sridhar Avatar asked Nov 26 '12 07:11

Sridhar


People also ask

How can I limit the height of spinner dropdown view in Android?

You can also affect drop down view location and size by subclassing Spinner and overriding its getWindowVisibleDisplayFrame(Rect outRect) which is used by android. widget. PopupWindow for calculations. Just set outRect to limit the area where drop down view can be displayed.


1 Answers

Kind of reviving an old post here but the accepted answer is far from ideal. The correct way to do this is to set the Spinner to dropdown mode in your layout xml:

<Spinner 
    android:id="@+id/my_spinner"
    ...
    android:spinnerMode="dropdown"/>

The available options are "dialog" and "dropdown".

like image 106
Stephen Kidson Avatar answered Nov 01 '22 08:11

Stephen Kidson