【问题标题】:Check a radio button according to a text根据文本检查单选按钮
【发布时间】:2016-12-10 06:23:26
【问题描述】:

在 Android Studio 中,我想根据从表格中获取的文本检查单选按钮。就像,如果它是表中的 MALE,请检查“MALE”或 FEMALE 的“FEMALE”。可能吗?如果可能的话,我该怎么做? 提前致谢。

【问题讨论】:

    标签: android android-studio radio-button


    【解决方案1】:

    你可能有这样的看法:

       <RadioGroup android:id="@+id/gender" 
            android:layout_width="match_parent"
            android:orientation="horizontal" 
            android:checkedButton="@+id/block_scenario_off"
            android:layout_height="wrap_content">
            <RadioButton 
                android:layout_width="0dip"
                android:layout_weight="1" 
                android:text="@string/male" 
                android:layout_height="wrap_content" 
                android:id="@+id/male"
                android:layout_gravity="center|left" 
                android:onClick="@string/on_click"/>
            <RadioButton 
                android:layout_width="0dip"
                android:layout_weight="1" 
                android:text="@string/female" 
                android:onClick="@string/on_click"
                android:layout_height="wrap_content"
                android:layout_gravity="center" 
                android:id="@+id/female"/>
    
        </RadioGroup>
    

    现在在函数上这样写:

    rgOption = (RadioGroup) findViewById(R.id.gender);
    String mGender = // get text whether it is male or female
    if(mGender.equals("Male"))
       rgOption.check(R.id.male);
    else 
       rgOption.check(R.id.female);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 2013-07-23
    • 2018-06-23
    • 2011-12-28
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    相关资源
    最近更新 更多