Apricot
Apricot

Reputation: 3011

Android Simple Spinner Dropdown Item

In my android app, I am using a spinner to render the name of the countries. The following are my codes:

XML

<Spinner
   android:id="@+id/intCountry"
   android:layout_weight="7"
   android:layout_width="0dp"
   android:layout_height="38dp"
   android:background="#FFFFFF"
   android:entries="@array/intCountry"
   android:layout_gravity="center_horizontal"
   android:textAppearance="?android:attr/textAppearanceMedium"
   />

Java - Version 1

//Country Spinner
        country = (Spinner) findViewById( R.id.intCountry );
        String[] countries = getResources().getStringArray( R.array.intCountry );
        ArrayAdapter<String> countryAdapter = new ArrayAdapter<>( this, R.layout.support_simple_spinner_dropdown_item, countries );
        countryAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
        country.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selCountry = (String) parent.getItemAtPosition(position);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        } );

Java - Version 2

//Country Spinner
        country = (Spinner) findViewById( R.id.intCountry );
        ArrayAdapter<CharSequence> countAdapter = ArrayAdapter.createFromResource( this,R.array.intCountry,android.R.layout.simple_spinner_dropdown_item );
        countAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        country.setAdapter( countAdapter );
        country.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selCountry = (String) parent.getItemAtPosition(position);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        } );

Both the options renders a simple and thin select option pop up. I am trying to derive a full screen select option with radio button style select option.

What I am getting is as follows:

enter image description here

What I want is this:

enter image description here

Upvotes: 0

Views: 347

Answers (1)

Bhavnik
Bhavnik

Reputation: 2048

Try this snippet, below line of code will set radio button in your spinner values

yourAdapterInstance.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);

and for full screen mode you can set this attribute in xml file

android:spinnerMode="dialog" // This will open spinner items in dialog.

Upvotes: 2

Related Questions