所以我有一个 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);
谢谢
最佳答案
你必须使用 Integer,而不是 int。此语法有效:
Integer[] items = new Integer[]{1,2,3,4};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, items);
关于java - 那么如何将一个int数组添加到android中的微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7490701/