2011-08-17 6 views
3

J'ai un radiogroupe et quand je vérifie quelqu'un dans le groupe je veux savoir lequel a été vérifié. Puis-je donner un ID à chacun d'entre eux? quand je mis en œuvre ce codeVérifiez quel radioButton a été vérifié IN ANDROID?

 

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

Je recevais un nombre aléatoire. Je n'ai pas pu identifier le radiobutton sur lequel j'ai cliqué. Est-ce qu'il y a un autre moyen?

Répondre

4

Vous pouvez attribuer id comme cet exemple de: http://developer.android.com/resources/tutorials/views/hello-formstuff.html#RadioButtons:

<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> 

Ensuite, comparez checkedId-R.id.radio_red (utilisez tout ce que vous réellement attribué à être bien).

Questions connexes