Igal
Igal

Reputation: 6083

Getting an ID of checked RadioButton in Android

I have a RadioGroup with 3 RadioButtons and a Button in my XML file. How can I get the ID of the checked RadioButton when I hit the Button (I have an OnClickListener set for this button)? Later I want to use Switch statement inside onClick, after checking which RadioButton is checked.

Thank you!

Upvotes: 0

Views: 230

Answers (2)

chrulri
chrulri

Reputation: 1832

Use getCheckedRadioButtonId() on your RadioGroup

Upvotes: 1

Mohsin Naeem
Mohsin Naeem

Reputation: 12642

you can use this

yourRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub

            }
        });

Upvotes: 1

Related Questions