2013-05-25 6 views
0

스피너가 첫 번째 스피너 선택을 기반으로 다른 스피너를 채우게 만드는 방법은 무엇입니까?회 전자에 다른 회 전자를 채우는 방법?

예 :

Spinner1 항목은 채식 또는 육식입니다.

<string-array name="spinnerarray_veg_meat"> 
    <item >Vegetarian</item> 
    <item >Meat eater</item> 
    </string-array> 

스피너 2는 스피너 1의 선택에 따라 채식 이름이나 고기 먹는 사람을 표시해야합니다.

+0

[이 (http://stackoverflow.com/questions 사용할 많은 유용한 기능과 특성을 갖는/13749805/using-two-android-spinners-one-dependent-on-the-other)이 유용 할 수 있습니다! – Oli

+0

감사합니다. 올리, 정말 도움이되었습니다. – user2406533

+0

비슷한 문제가있는 사람은 위의 Oli의 링크를 참조하십시오. – user2406533

답변

1

첫 번째 SpinnerOnItemSelectedListener을 설정하여 두 번째로 프로그래밍 방식으로 Spinner을 채워야합니다.

spinner1.setOnItemSelectedListener(new OnItemSelectedListener() { 

     public void onItemSelected(AdapterView<?> parent, View view, 
       int position, long id) { 

       if(position == 0) { 
        // Populate the Spinner2 with different values 
       } else { 
        // Populate the Spinner2 with different values 
       } 

     } 
     public void onNothingSelected(AdapterView<?> parent) { 
      return; 

     } 
    }); 
0

여러 가지 방법이 있습니다. 하나는 고기 항목과 야채 항목 중 하나를 Array으로 만듭니다. spinner1onItemSelected()에서 position

Spinner Docs

이 링크에 따라 spinner2 용 어댑터를 설정 Spinner S

관련 문제