我有以下代码。当我运行我的程序时,我只在spinner下拉列表中获得一个元素。
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
spinnerCountShoesArrayAdapter = new ArrayAdapter<String>(
PatientRegistration.this,
android.R.layout.simple_spinner_dropdown_item,
getResources()
.getStringArray(R.array.locality_contents));
spinnerCountShoesArrayAdapter = new ArrayAdapter<String>(
PatientRegistration.this,
android.R.layout.simple_list_item_1, DayOfWeek);
b.setAdapter(spinnerCountShoesArrayAdapter);
答案 0 :(得分:1)
试试此代码
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
ArrayAdapter<String> spinnerCountShoesArrayAdapter = new ArrayAdapter<String>(
PatientRegistration.this,
android.R.layout.simple_spinner_item, DayOfWeek);
spinnerCountShoesArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
b.setAdapter(spinnerCountShoesArrayAdapter);
答案 1 :(得分:0)
只需添加以下代码行,即可使用
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
spinnerCountShoesArrayAdapter = new ArrayAdapter<String>(
PatientRegistration.this,
android.R.layout.simple_dropdown_item_1line);
for (int i = 0; i < DayOfWeek.length(); i++) {
spinnerCountShoesArrayAdapter.add(DayOfWeek[i]);
}
b.setAdapter(spinnerCountShoesArrayAdapter);