Home > Enterprise >  How to get text of the checked id from radio group using view binding?
How to get text of the checked id from radio group using view binding?

Time:01-21

I had gone through this and found a common answer i.e

        int selectedId = radioGroup.getCheckedRadioButtonId();

        radioButton = (RadioButton) findViewById(selectedId);

        Toast.makeText(MyAndroidAppActivity.this,
            radioButton.getText(), Toast.LENGTH_SHORT).show();

But how to get text using view binding?

CodePudding user response:

You could do this:

EDIT:

int id = binding.radioGroup.getCheckedRadioButtonId();
RadioButton radioButton = binding.getRoot().findViewById(id);
//Then get the radio button's text
Toast.makeText(MyAndroidAppActivity.this,
        radioButton.getText(), Toast.LENGTH_SHORT).show();
  •  Tags:  
  • Related