我有一个带有三个微调器的应用程序,它们具有唯一的 ID,我正在尝试使用以下代码来初始化它们:
Spinner spinner = (Spinner) findViewById(R.id.spinDouble);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.double_nums, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Spinner spinner2 = (Spinner) findViewById(R.id.spinReroll);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.reroll_nums, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);
Spinner spinner3 = (Spinner) findViewById(R.id.spinTarget);
ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.target_nums, android.R.layout.simple_spinner_item);
adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner3.setAdapter(adapter);
spinTarget.setSelection(3);
它们初始化并填充了值,确实如此,但是查看 strings.xml 中的数组:
<string-array name="reroll_nums">
<item>10</item>
<item>9</item>
<item>8</item>
<item>7</item>
<item>6</item>
<item>5</item>
<item >4</item>
<item >3</item>
<item >2</item>
</string-array>
<string-array name="double_nums">
<item>10</item>
<item>9</item>
<item>8</item>
<item>7</item>
<item>6</item>
<item>5</item>
<item >4</item>
<item >3</item>
<item >2</item>
<item >1</item>
</string-array>
<string-array name="target_nums">
<item>10</item>
<item>9</item>
<item>8</item>
<item>7</item>
<item>6</item>
<item>5</item>
<item >4</item>
<item >3</item>
<item >2</item>
<item >1</item>
</string-array>
Spinner #2 (spinReroll) 的值应该是 2-10,而其他的值应该是 1-10,但是当我在我的虚拟设备中运行这个应用程序时,所有三个微调器都有 1-10 的值,因为选择 1in 在spinReroll 创建一个无限循环:P
我做错了什么?