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);
答案 0 :(得分:1)
使用countryList
元素创建Select One
数组。等,
String[] countryList = new String[]{"Select One" ,"India" , "China" , "Japan"};
这可能有助于你
答案 1 :(得分:0)
添加&#34;选择一个&#34;作为列表中的第一项,即countryList
答案 2 :(得分:0)
将微调器的第一项添加为“Select One”,并在onclick监听器中设置如下所述的条件。
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) {
}
});