2014-06-09 2 views
0

하나의 페이지에 2 개의 스피너를 만들려고합니다. 내 코드는 onItemSelected; 나는이 프로그램을 실행할 때 예상대로Android 여러 개의 스피너 (1 클래스)

@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; 
     } 
    } 
    } 

하지만, 사건은, 예를 응답하지 않는 회 전자 (2)는 다음과 같이이며, 그것이 내가 대답 나 자신을 발견

+0

"스피너 2가 화면 3으로 전송합니다."... 올바른 소리로 ... 코드를 확인하고 spinner2에게 Screen3.class의 의도를 실행 시키라고 말했습니다. – ElDuderino

답변

1

화면 2로 이동해야 할 때 SCREEN3로 전송 :

int a = arg0.getId(); 

    if (a==R.id.spinner1){ 
     switch(arg2) { 

//Do something 
           } 

    if (a==R.id.spinner2){ 
     switch(arg2) { 

//Do something 
           }