Check which radioButton was checked IN ANDROID?
i have a radiogroup and when I check anyone in the group I want to know which one was checke开发者_StackOverflow社区d. Can I give each one an id. when I implemented this code
public void onCheckedChanged(RadioGroup group, int checkedId) { mChoice.setText(checkedId+""); }
I was getting some random number. I was not able to identify which radiobutton I clicked. Is there anyother way?
You can assign id's like this example from: 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>
Then compare checkedId
to R.id.radio_red
(use whatever you actually assigned it to be though).
精彩评论