2011-08-17 7 views
3

나는 radiogroup을 가지고 있는데 그룹에있는 사람을 확인할 때 어느 것이 체크되었는지 알고 싶다. 각각에게 ID를 부여 할 수 있습니까? 이 코드ANDROID에 어떤 radioButton이 선택되어 있는지 확인하십시오.

 

    public void onCheckedChanged(RadioGroup group, int checkedId) { 
     mChoice.setText(checkedId+""); 
    } 

좀 임의의 숫자를 얻고 있었다 구현 . 내가 클릭 한 라디오 버튼을 식별하지 못했습니다. 다른 방법이 있습니까? http://developer.android.com/resources/tutorials/views/hello-formstuff.html#RadioButtons :

답변

4

당신은에서이 예제와 같이 아이디의 할당 할 수 있습니다

<RadioGroup 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <RadioButton android:id="@+id/radio_red" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Red" /> 
    <RadioButton android:id="@+id/radio_blue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Blue" /> 
</RadioGroup> 

그런 checkedIdR.id.radio_red에 (당신이 실제로 비록 수를 할당 무엇이든 사용)를 비교합니다.

관련 문제