11

I used radio button for language selection.

  • English
  • Hindi
  • Tamil

When I click English the radio button of English should be disabled. Again I should not able to click the English radio button till I click the next language it should be in disabled position. In Java code I need.I created the xml file.

3
  • Please post some code... Commented Jun 19, 2013 at 11:57
  • 2
    Sounds weird... Clicking a radio button should disable it? Hardly makes sense to me. Commented Jun 19, 2013 at 11:58
  • Why with radio button, its only one select no meaning to disable Commented Jun 19, 2013 at 12:07

6 Answers 6

15
findViewById(R.id.buttonEng).setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
    Button btnEng=(Button)findviewById(R.id.btnEng);
    btnEng.setEnabled(false);
}
});

Is this what you asked for? If yes, then that's the code. Then just re-enable it when the other buttons are clicked.

2

To enable and Disabled Radio Group write this code.

// To disabled the Radio Buttons of radio group.
        for (int i = 0; i < radioUser.getChildCount(); i++) {
            radioUser.getChildAt(i).setEnabled(false);
        }

where radioUser=RadioGroup

1

try this:-

 private void Disable_Or_Enable_RG_Button(RadioGroup radioGroup,boolean enable_or_disable){
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        ((RadioButton) radioGroup.getChildAt(i)).setEnabled(enable_or_disable);
    }
}

 Disable_Or_Enable_RG_Button(rg_group,false) // for disable all radio button.
 Disable_Or_Enable_RG_Button(rg_group,true) // for enable all radio button.
1

Activate a click listener for the radioButton by setting radioButton.setOnclickListner for that radioButton and then call the radioButton.setEnabled(false) method inside the listener. You will have to do this for each Tamil,English and Hindi radio buttons individually.

-1

You can use radio button group for this. It will be better option.

3
  • Will u guys give more clearly.Radio group will disable all radio buttons i need single radio button to be disabled Commented Jun 19, 2013 at 12:59
  • 2
    Samadhan's suggestion doesn't seem to work. I tried final RadioGroup radioGroup1 = (RadioGroup)view.findViewById(R.id.radiogroup1); radioGroup1.setEnabled(false); but it doesn't disable the buttons in the group Commented Dec 27, 2013 at 22:18
  • To disable a group, see this: stackoverflow.com/questions/13261602/…
    – Max
    Commented Jan 22, 2018 at 15:52
-1

Here is your solution

  1. myRadioButton.isClickacle(false) in java
  2. myRadioButton.isClickable = false in kotlin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.