3

I want to set my RadioGroupView to not clickable so that the user can't click on the buttons. I tried mRadioGroup.isActivated = false but it has no effect on my RadioGroup View. Have somebody a hint for me?

dudi
  • 5,523
  • 4
  • 28
  • 57

5 Answers5

4

Disable for each button

for (int i = 0; i < mRadioGroup.getChildCount(); i++) {
    mRadioGroup.getChildAt(i).setEnabled(false);
}
Prithvi Bhola
  • 3,041
  • 1
  • 16
  • 32
2

Have you tried set RadioGroupView clickable = false? If it's not working, you can put a View overlay whole RadioGroup layout and set this view clickable = true.

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
2

In order to disable the radio buttons inside radio group you need to manually disable each button with the help of radioButton1.setEnabled(false) method. However better way is to loop through the radio buttons inside mRadioGroup with the help of getChildAt() method

for (int i = 0; i < mRadioGroup.getChildCount(); i++){
 mRadioGroup.getChildAt(i).setEnabled(false); 
}
Deepam Goel
  • 135
  • 1
  • 4
  • 8
1

Building on Prithvi Bhola's answer you can use a Kotlin extension function that you simply add to your Activity:

fun RadioGroup.setChildrenEnabled(enabled: Boolean) {
    for (i in 0 until childCount) {
       getChildAt(i).isEnabled = enabled
    }
}

Then, whenever you need to you can simply disable or enable all RadioButtons in the RadioGroup:

mRadioGroup.setChildrenEnabled(false)
Markus Penguin
  • 1,581
  • 12
  • 19
0

RadioGroup cannot be disabled directly, we have to loop through the radio button and set it enabled as false.

Try this:

for(int i = 0; i < rg.getChildCount(); i++){
    ((RadioButton)rg.getChildAt(i)).setEnabled(false);
}

Hope this will help.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50