簡體   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?

我有一個廣播組,在這個廣播組中,我有兩個單選按鈕。 我想使此單選按鈕不可用於特定用戶。 請幫我。

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);
        }


        }

我已經嘗試過此代碼,並且我的角色ID是我要用於特定用戶的即時消息,因為我希望此單選按鈕不可點擊。 但是,如果我不使用角色ID,則對所有用戶都禁用它。 但我想要特定的用戶。 請幫我

 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);

當我使用屬性setOnCheckedChangeListener(false)時顯示錯誤,例如不能在布爾值中使用false。 所以請幫我

在您的案例中同時使用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);
}

你可以試試這個

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

整數RoleID = 19;
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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM