2011-08-17 28 views
3

我有一個radiogroup,當我檢查組中的任何人時,我想知道哪一個被檢查過。 我可以給每個人一個ID。 當我實現了這個代碼檢查哪個radioButton被檢查過IN ANDROID?

 

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

我得到了一些隨機數。 我無法確定我點擊了哪個單選按鈕。有沒有其他辦法?

回答

4

您可以分配的ID喜歡從這個例子: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> 

然後比較checkedIdR.id.radio_red(使用任何你實際分配它是雖然)。