I have a need to add 3 related spinners where the selected content in the first affects what is displayed in the second and then what is selected in the second affects the content in the third. Has anyone already faced this problem and how did you over come it?
开发者_运维技巧I was thinking of maintaining a number of arrays in the resources which are numbered and then loaded into the adapter based on the choice selected in the previous spinner. Is this a good way?
Thanks, m
I would have done this with something like that:
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...);
}
});
精彩评论