检查哪个radioButton被检查IN ANDROID?

时间:2011-08-17 17:03:51

标签: android

我有一个无线电组,当我检查组中的任何人时,我想知道哪一个被检查了。 我可以给每个人一个id。 当我实现这段代码时


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

我得到了一些随机数。 我无法确定我点击了哪个单选按钮。还有其他办法吗?

1 个答案:

答案 0 :(得分: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进行比较(使用您实际指定的任何内容)。