Android radio button on and off

I used the switch to select the language.

  • English
  • Hindi
  • Tamil

When I click on English, the English radio button should be disabled. Again, I could not click the English radio button until we click on the next language. must be in the off position. In Java code I need. I created an xml file.

+9
source share
5 answers
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 that what you asked for? If so, then this is the code. Then just re-enable it when you press other buttons.

+13
source

try it: -

  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
source

To enable or disable a 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

0
source

Activate the click listener for radioButton by setting radioButton.setOnclickListner for that radioButton, and then call the radioButton.setEnabled (false) method inside the listener. You will need to do this for each button in Tamil, English and Hindi separately.

0
source

You can use a group of radio buttons for this. This will be the best option.

-1
source

Source: https://habr.com/ru/post/947648/


All Articles