Search code examples
androidandroid-studiokotlinradio-buttonradio-group

checkedRadioButtonID integer to string in output Kotlin


I have a basic survey app that emails results upon hitting the submit button at the end. In the string that is built it calls the result of the checked radio button to put into the email, but it's showing as an integer instead of the button text.

Currently:

val id = group1.checkedRadioButtonId

returns 213120809 or 2131230810 depending on which response is checked

I've tried to add getString() to it so like so:

val id = group1.checkedRadioButtonId.getString()

but that doesn't seem to do anything. Does anyone know if there's another command I should be using? This is in Kotlin.


Solution

  • There is no property to get selected button text.

    You can get it like this

    val radioButtonText = when (group1.checkedRadioButtonId) {
                             R.id.radioButton1 -> radioButton1.text
                             else -> radioButton2.text
                          }