我正在尝试使用整数值创建一个Spinner(1,5,10等) 我已经有一个带字符串的Spinner,一切都运行良好。
private static final String[] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Spinner spinner_days =(Spinner)findViewById(R.id.spinner_days);
spinner_days.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, daysOfWeek);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_days.setAdapter(aa);
当我尝试用
做同样的事情时private static final int[] options = {1, 3, 5, 10, 15, 20, 30, 40, 45, 50, 60};
然后当我尝试创建ArrayAdapter时出现错误,因为我认为只能用String数组做到这一点?
有人可以帮帮我吗?
谢谢!
答案 0 :(得分:4)
您无法创建ArrayAdapter
的整数,因此您可以尝试使用数字来创建一个字符串数组。试试这个 -
public static final String [] options = {"1", "3", "5", "10", "15", "20", "30", "40", "50", "60"}
或者,您可以使用Integer
代替int
Integer[] options = new Integer[]{1, 3, 5, 10, 15, 20, 30, 40, 50, 60};