Reputation: 9
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);
Upvotes: 0
Views: 1414
Reputation: 2648
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) {
}
});
Upvotes: 1
Reputation: 4345
Create your countryList
array with Select One
element. like,
String[] countryList = new String[]{"Select One" ,"India" , "China" , "Japan"};
This may helps you
Upvotes: 2
Reputation: 33438
Add "Select One" as the first item in your list i.e. countryList
Upvotes: 0