简体   繁体   English

我有一个广播组,在这个广播组中,我有两个单选按钮。 如何在Android中使单选按钮不可点击?

[英]I have a radio group and in this radio group i have two radio buttons. how can i make Radio Button non-clickable in android?

I have a radio group and in this radio group i have two radio buttons. 我有一个广播组,在这个广播组中,我有两个单选按钮。 I want make this radio button non-clickable for particular user. 我想使此单选按钮不可用于特定用户。 Please help me. 请帮我。

installation_Satisfactory=(RadioGroup)findViewById(R.id.installation_satisfactory);

        if (roleID==19)
        {
            for(int i = 0;  i < installation_Satisfactory.getChildCount(); i++){
                ((RadioButton)installation_Satisfactory.getChildAt(i)).setEnabled(false);
        }


        }

I have tried this code and my role id is im using for particular user for that i want this radio button non-clickable. 我已经尝试过此代码,并且我的角色ID是我要用于特定用户的即时消息,因为我希望此单选按钮不可点击。 But if i'm not using role id it disabled for all users. 但是,如果我不使用角色ID,则对所有用户都禁用它。 but i want for particular user. 但我想要特定的用户。 Please help me 请帮我

 if(Integer.parseInt(viewInspectionSheetModel.getInstallationSatisfactory())==1)


                            installation_Satisfactory.check(R.id.installation_yes);


                       if(Integer.parseInt(viewInspectionSheetModel.getInstallationSatisfactory())==0)
                            installation_Satisfactory.check(R.id.installation_no);

while i am using property setOnCheckedChangeListener (false) is showing error like can't use false in boolean. 当我使用属性setOnCheckedChangeListener(false)时显示错误,例如不能在布尔值中使用false。 so please help me 所以请帮我

Use both if and else for your case to solve your isssue. 在您的案例中同时使用if和else来解决问题。

if (roleID==19)
{
    for(int i = 0;  i < installation_Satisfactory.getChildCount(); i++){
        ((RadioButton)installation_Satisfactory.getChildAt(i)).setEnabled(false);
} else
{
    for(int i = 0;  i < installation_Satisfactory.getChildCount(); i++){
        ((RadioButton)installation_Satisfactory.getChildAt(i)).setEnabled(true);
}

you can try this 你可以试试这个

 radioButton1.setEnabled(false);
 radioButton2.setEnabled(true);

int RoleID =19; 整数RoleID = 19;
RadioGroup radioSexGroup = (RadioGroup) findViewById(R.id.radioSex); RadioGroup radioSexGroup =(RadioGroup)findViewById(R.id.radioSex);

        radioSexGroup.getChildCount();
        for(int i=0;i<radioSexGroup.getChildCount();i++)
        {
            RadioButton radioButton = (RadioButton)radioSexGroup.getChildAt(i);
            if(RoleID==19)
            {
                if(radioButton.getId() == R.id.installation_satisfactory)
                {
                    radioButton.setEnabled(false);
                }
            }
        }

xml :
<RadioGroup
        android:id="@+id/radioSex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/installation_satisfactory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="male"
             />

        <RadioButton
            android:id="@+id/radioFemale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="female" />

    </RadioGroup>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何确保从单选按钮组中选择单选按钮会影响其他单选按钮组中单选按钮的选择。 - How do i ensure that the selection of a radio button from a radio group affects the selection of a radio button in a different radio group. 如何获取从 Android 中的单选组检查的最后一个单选按钮? - How do i get the last radio button that was checked from a radio group in Android? 在没有无线电组的情况下,我如何 select 适配器 class 中的一个单选按钮 - How can I select one Radio Button in adapter class without Radio Group 如何在Android中用Java代码创建一个Radio组? - How can i create a Radio group in java code in Android? 在 Android 中选中单选按钮时,如何取消选中单选组中的所有单选按钮? - How to uncheck all radio buttons in a radio group, when a radio button is checked in Android? 单选组未设置为Android单选按钮 - Radio group not setting to radio buttons Android 我对每个单选按钮都有相同的答案 - I have the same answers on each Radio Button 是否可以让单选按钮彼此不相邻但仍可在同一个单选组中工作? - Can you have Radio Buttons that are not beside each other but still work in one radio group? 如何在按钮组中添加单选按钮? - How to add radio buttons in button group? 我想通过选择该组的单选按钮来获取无线电组的ID,我正在动态创建它们 - I want to get the id of radio group by selecting the radio button of that group, i am creating both dynamically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM