影响基于第一微调微调第二选择 [英] Affect Second Spinner Choices based on First Spinner
本文介绍了影响基于第一微调微调第二选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我可以看到有这个问题,但不是在我的范围。我栋为Android有两个微调器的应用程序。第一有更多选择的阵列。但是,我不知道如何影响到第二个具有基于第一个选择是什么。我知道,你可以把
So I can see that there are questions about this, but not in the scope of mine. I am buliding an app for Android that has two spinners. The first has an array of choices. However, I am not sure how to affect what choices the second one has based on the first one. I know that you can put in
AdapterView.OnItemSelectedListener
但我不知道如何实现这一点。我读过这个,但它并不完全符合我要找的。我也好奇,我怎么告诉微调阵列选择哪个,它是在.xml或在java文件?
but I'm not sure how to implement this. I've read on this but it's not quite what I'm looking for. I'm also curious as to how I tell the spinner which array to choose, is it in the .xml or in the .java file?
推荐答案
试试这个,
firstSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
string selectedValue = arg0.getSelectedItem().toString();
if(selectedValue.equalsIgnoreCase(string1)
{
ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, firstArray);
secondSpinner.setAdapter(firstAdapter);//
}
else if(selectedValue.equalsIgnoreCase(string2)
{
ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, array2);
secondSpinner.setAdapter(firstAdapter);
}
}
希望它会帮助你。
Hope it will help you.
这篇关于影响基于第一微调微调第二选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文