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);
Asked
Active
Viewed 1,396 times
0

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

Faheem Ahmad
- 9
- 4
-
1Please add some description to the question. – K Neeraj Lal Jul 12 '16 at 06:08
-
@Faheem Ahmad try with my answer http://stackoverflow.com/a/38321179/3981656 – Sathish Kumar J Jul 12 '16 at 06:21
3 Answers
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
-
-
-
-
refer here http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one – Sathish Kumar J Jul 12 '16 at 10:01
-
if it's helpful means kindly mark as answer. so other can find answer easily. – Sathish Kumar J Jul 12 '16 at 11:40
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