我想在一个页面上创建2个微调器。我的代码在onItemSelected;
下面@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch(arg0.getId()) {
case R.id.spinner1:
switch(arg2){
case 0:
Toast.makeText(this, "THIS IS SPINNER 1" , Toast.LENGTH_SHORT).show();
break;
case 1:
Intent intent1 = new Intent(this, Screen2.class);
startActivity(intent1);
break;
case 2:
Intent intent2 = new Intent(this, Screen2.class);
startActivity(intent2);
break;}
case R.id.spinner2:
switch(arg2){
case 0:
Toast.makeText(this, "THIS IS SPINNER 2" , Toast.LENGTH_SHORT).show();
break;
case 1:
Intent intent1 = new Intent(this, Screen3.class);
startActivity(intent1);
break;
case 2:
Intent intent2 = new Intent(this, Screen3.class);
startActivity(intent2);
break;
}
}
}
但是当我运行该程序时,案例没有像我预期的那样响应,例如,当它应该转到screen2时,spinner 2将它发送到screen3
答案 0 :(得分:1)
我自己找到了答案,如下:
int a = arg0.getId();
if (a==R.id.spinner1){
switch(arg2) {
//Do something
}
if (a==R.id.spinner2){
switch(arg2) {
//Do something
}