M. Conneely
M. Conneely

Reputation: 1

How to get text from a radio button in android

So I'm writing an app that requires me to have a radio group, and when a certain radio button is clicked in that group, points get added to the total.

So far, I have

int radiobuttonid = rg.getCheckedRadioButtonId();
rb = (RadioButton) findViewbyId(radiobuttonId);

This is to get what radio button is pressed, but I have no idea how to get a string/text from the button to form my if-else statements. Any ideas?

Upvotes: 0

Views: 816

Answers (1)

user8743642
user8743642

Reputation:

Use the following code. If there is no text. it will return an empty string ""

((RadioButton) findViewbyId(radiobuttonId)).getText().toString()

Upvotes: 3

Related Questions