0

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

Apricot
  • 2,925
  • 5
  • 42
  • 88
  • Does this answer your question? [How to customize a Spinner in Android](https://stackoverflow.com/questions/16694786/how-to-customize-a-spinner-in-android) – Walid Jul 06 '20 at 11:18

1 Answers1

2

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.
Bhavnik
  • 2,020
  • 14
  • 21