[英]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.