pic*_*and 2 java android spinner
所以我有一个int数组和一个微调器,我需要微调器来显示int数组的值.作为一个新手,我不知道如何将int数组添加到arrayadapter或simpleadapter.我也可以使用列表而不是数组,但它总是包含整数值.
mspin=(Spinner) findViewById(R.id.spinner1);
int[] items=new int[]{1,2,3,4};
ArrayAdapter<int[]> ad=new ArrayAdapter(this,android.R.layout.simple_spinner_item);
//ad.add(items); // this cause some value to be displayed, possible the id of the item.
mspin.setAdapter(ad);
Run Code Online (Sandbox Code Playgroud)
谢谢
ggu*_*rov 12
你必须使用Integer,而不是int.此语法有效:
Integer[] items = new Integer[]{1,2,3,4};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, items);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5986 次 |
最近记录: |