我需要添加3个相关的微调器,其中第一个中的选定内容会影响第二个中显示的内容,然后第二个选择的内容会影响第三个中的内容。有没有人已经遇到过这个问题,你是怎么过来的?
我在考虑在资源中维护一些数组,这些数组已编号,然后根据前一个微调器中选择的选项加载到适配器中。这是一个好方法吗?
谢谢, 米
答案 0 :(得分:2)
我会用这样的东西做到这一点:
spinner1.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
SpinnerAdapter adapter = ...create or load the second adapter based on selected item...
spinner2.setAdapter (adapter);
spinner3.setAdapter (..create empty adapter...);
}
@Override
public void onNothingSelected(AdapterView<?> parentView)
{
spinner2.setAdapter (..create empty adapter...);
spinner3.setAdapter (..create empty adapter...);
}
});
spinner2.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
SpinnerAdapter adapter = ...create or load the third adapter based on selected item...
spinner3.setAdapter (adapter);
}
@Override
public void onNothingSelected(AdapterView<?> parentView)
{
spinner3.setAdapter (..create empty adapter...);
}
});