【问题标题】:Why RadioGroup Selecting multiple RadioButtons为什么 RadioGroup 选择多个 RadioButtons
【发布时间】:2017-01-14 17:32:01
【问题描述】:

我在 RadioGroup 下添加了 2 个 RadioButtons 并启用了第一个,当我选择第二个时,它不会取消选择第一个。你能告诉我这有什么问题吗

这是我的 xml:

<RadioGroup 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="horizontal">
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="NO"/>
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="YES"/>
</RadioGroup>

【问题讨论】:

  • 您的RadioButtons 需要 ID。

标签: android radio-button radio-group


【解决方案1】:

只需为所有单选按钮提供 ID。它会起作用的。

android:id="@+id/radioButton1/2/3"

【讨论】:

    【解决方案2】:

    去掉 android:checked="true" 应该就好了

    【讨论】:

      【解决方案3】:

      试试这个:

      <RadioGroup 
              android:id="@+id/radioGrp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:orientation="horizontal">
              <RadioButton 
                  android:id="@+id/radio1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:checked="true"
                  android:text="NO"/>
              <RadioButton 
                  android:id="@+id/radio2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="YES"/>
      </RadioGroup>
      

      【讨论】:

        【解决方案4】:

        我认为android:checked="true" 使其被无限选择。
        尝试默认代码中的第一个按钮。

        radiogroup.check(idOfYourFirstRadio)
        


        您需要为视图设置 ID。

        【讨论】:

          猜你喜欢
          • 2013-06-14
          • 1970-01-01
          • 2012-04-14
          • 1970-01-01
          • 2016-04-07
          • 2012-05-12
          • 2016-06-28
          • 2013-07-15
          相关资源
          最近更新 更多