0
ArrayAdapter<StringWithTag> spinnerAdapter = new ArrayAdapter<StringWithTag>(RegisterActivity.this, android.R.layout.simple_spinner_item, countryList);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinnerCountry.setAdapter(spinnerAdapter);
Viral Patel
  • 32,418
  • 18
  • 82
  • 110

3 Answers3

2

Create your countryList array with Select One element. like,

String[] countryList = new String[]{"Select One" ,"India" , "China" , "Japan"};

This may helps you

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
1

Add first item of the spinner as "Select One" and in onclick listener set the condition as mentioned below.

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (position == 0)
            {
               Toast.makeText(getApplicationContext(),"Please Select any one option",Toast.LENGTH_SHORT).show();
            }
            else if (position == 1)
            {
                // add you stuff
            }
            else {
                // add your stuff
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
Tara
  • 2,598
  • 1
  • 21
  • 30
0

Add "Select One" as the first item in your list i.e. countryList

Viral Patel
  • 32,418
  • 18
  • 82
  • 110