这段代码是否正确
static_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
option=static_spinner.getSelectedItem().toString();
switch (option){
case "option1":
adapter = ArrayAdapter.createFromResource(Upload.this,R.array.list11,android.R.layout.simple_spinner_item);
break;
case "option2":
adapter = ArrayAdapter.createFromResource(Upload.this,R.array.list22,android.R.layout.simple_spinner_item);
break;
case "option2":
adapter = ArrayAdapter.createFromResource(Upload.this,R.array.list33,android.R.layout.simple_spinner_item);
break;
case "option3":
adapter = ArrayAdapter.createFromResource(Upload.this,R.array.list44,android.R.layout.simple_spinner_item);
break;
}
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_dynamic.setAdapter(adapter);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
list11,list22,list33和list44在字符串中指定为数组。
我想根据static_spinner中的选择将其中一个数组指定为spinner_dynamic的条目。
有没有办法实现这个目标?