【问题标题】:Check which radioButton was checked IN ANDROID?检查在ANDROID中检查了哪个radioButton?
【发布时间】:2011-10-29 03:07:09
【问题描述】:

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

公共无效 onCheckedChanged(无线电组组,int checkId){ mChoice.setText(checkedId+""); }

我得到了一些随机数。 我无法识别我单击了哪个单选按钮。有没有其他办法?

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以从以下示例中分配 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 进行比较(使用您实际指定的任何值)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 2015-07-06
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      相关资源
      最近更新 更多