【问题标题】:How to select a button from RadioGroup [duplicate]如何从 RadioGroup 中选择一个按钮 [重复]
【发布时间】:2021-10-04 22:03:04
【问题描述】:

如何从 RadioGroup 中选择单个项目。我分享了一个示例代码。我们将不胜感激。

<RadioGroup
    android:id="@+id/gender"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/custom_edit_text"
    android:orientation="horizontal">

    <RadioButton
        android:id="@+id/male"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/male" />

    <RadioButton
        android:id="@+id/female"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/female" />

</RadioGroup>

【问题讨论】:

    标签: android


    【解决方案1】:
    RadioGroup gender = findViewById(R.id.updateGender);
    
    if(condition_for_male) {
        gender.check(R.id.male);
    } else {
        gender.check(R.id.female);
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 2021-11-08
      • 2014-02-07
      • 2014-03-18
      • 2012-11-05
      • 1970-01-01
      • 2013-11-22
      • 2016-04-07
      • 2012-07-14
      相关资源
      最近更新 更多