Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spinner shows like dialog

I am using the spinner and it opens like a dialog. I need spinner to be open like dropdown menu.

Here is the xml file

 <Spinner
 android:id="@+id/sp_countrycode_issue_coupon"
 android:layout_width="60dp"
 android:layout_height="40dp"
 android:layout_gravity="center"
 android:layout_marginLeft="3dp"
 android:layout_weight="1"
 android:background="@drawable/img_small_box_green"
 android:dropDownSelector="@drawable/img_small_box_green"
 android:gravity="right|center"
 android:textAlignment="center" />

Here is the code

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.country_code,
            android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(R.layout.spinner_textview);
sp_country_code.setAdapter(adapter);

I posted my images bellow like my view and spinner display view. But I need the spinner to be display like the third image

Here is my layoutSpinner displays in this wayBut I need in this format

like image 868
Kartheek s Avatar asked Jul 02 '13 06:07

Kartheek s


3 Answers

For the information Dropdown spinner that you shown in Image 3 is applicable from version 3.0 and above. For previous versions like 2.2 and 2.3 it will open like dialog. It will automatically show dropdown in versions above 2.3

Styles will be automatically added if you choose android version 4.0 or above.

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>    

enter image description here

Refrence code

    severitySpinner = (Spinner) findViewById(R.id.spinnerSeverity);
    severityAdapter = ArrayAdapter.createFromResource(this,
            R.array.severity_arrays, android.R.layout.simple_spinner_item);
    severityAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    severitySpinner.setAdapter(severityAdapter);

Edit

<application
        android:icon="@drawable/appicon"
        android:label="Test"
        android:theme="@style/AppTheme" >
like image 96
Nirali Avatar answered Oct 13 '22 07:10

Nirali


Late but may be useful to other people, you can simply set the spinnerMode to dropdown:

android:spinnerMode="dropdown"

Else, if you decided you fancied a change and wanted dialog in the future just change the mode to dialog!

like image 36
Connor McFadden Avatar answered Oct 13 '22 05:10

Connor McFadden


in manifest file change theme to android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" and in xml file set style for spinner style="@style/MyDropDownNav" and in style file add style.

<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner">
    <item name="android:popupBackground">@drawable/bg_popup</item>
    <item name="android:dropDownSelector">@drawable/top_layout</item>
</style>
like image 23
Zulfiqar Chandio Avatar answered Oct 13 '22 06:10

Zulfiqar Chandio