好的离心器1使用Manu_array 旋转器2使用马努1xsd,马努2xrsd或3x4rsd 所有我需要现在是能够填充所述第二旋转器在旋转器从Manu_array选择一个值之后1.Spinner1从阵列填充,然后,基于第一旋转器选择来选择第二阵列,用于spinner2
<!--for spinner 1-->
<string-array name="Manu_array">
<item>Manu 1xsd</item>
<item>Manu 2xrsd</item>
<item>Manu 3x4rsd</item>
</string-array>
<!--for spinner 2-->
<string-array name="Manu 1xsd">
<item>a1</item>
<item>a2</item>
<item>a3</item>
<item>a4</item>
</string-array>
<string-array name="Manu 2xrsd">
<item>bg 1</item>
<item>bg 2</item>
</string-array>
<string-array name="Manu 3x4rsd">
<item>z1</item>
<item>z2</item>
<item>zd4</item>
<item>xs5</item>
<item>fg34</item>
</string-array>
我的Java代码文件:
final Spinner[] spinner1 = {(Spinner) findViewById(R.id.spinner1)};
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.Manu_array, R.layout.textview);
spinner1[0].setAdapter(adapter);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner1[0].setAdapter(adapter);
spinner1[0].setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int index = arg0.getSelectedItemPosition();
// storing string resources into Array
Manu= getResources().getStringArray(R.array.Manu_array);
Toast.makeText(getBaseContext(), "You have selected : " + Manu[index],
Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// do nothing
}
});
我可以处理代码,将允许微调器与阵列的数据填充,但我不能得到的第二个微调器基于第一个微调器的选择进行填充,当然它的简单如果等于值使用数组。
上面的微调器显示的是Manu_array的值,下一个微调器必须采用所选的值并填充相应的数组值,但我所能做的就是生成第二个带数组值的微调器。键入,未选中。
if(Manu.equals("Manu 1xsd")){spinner2 languages = getResources().getStringArray(R.array.Manu 1xsd_array)}else......
任何建议,我可能会寻找的例子,请看看这里的几个,让我困惑的东西慢性。
填充你的第二个微调第一微调的itemSelected方法中 –
感谢,我想我已经看过这方面的例子,但不能跟随当第二微调适配器它,我会再看看。 – MadWayne