【问题标题】:Radio button in androidandroid中的单选按钮
【发布时间】:2013-01-09 18:15:39
【问题描述】:

我有一组单选按钮,我在布局中动态创建单选按钮。这是我想要的,当我选中一个单选按钮时,应该取消选中其他单选按钮。如何使用单选按钮数组来操作它?请身体帮忙!

这是图片。单选按钮不会自动取消选中。

【问题讨论】:

    标签: android radio-button


    【解决方案1】:

    将所有这些 RadioButtons 放入 RadioGroup

    【讨论】:

      【解决方案2】:

      RadioButtons 会自动执行此操作,但您必须将它们分组到 RadioGroup 中: http://developer.android.com/intl/es/reference/android/widget/RadioGroup.html

      【讨论】:

        【解决方案3】:

        是的,RadioButtons 会自动执行此操作。这是供您参考的代码。希望对你有帮助。

          <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" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-02-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-29
          • 2015-03-03
          相关资源
          最近更新 更多