Event listeners for RadioButton

Report a typo

Can you identify the Kotlin code snippet that shows how to manage a RadioButton's selection in an Android activity using a RadioGroup?

A

radioGroup.setOnCheckedChangeListener { _, checkedId ->
    when (checkedId) {
        R.id.radioWhite -> {
            // ...
        }
        R.id.radioBlack -> {
            // ...
        }
    }
}

B

radioGroup.setOnCheckedChangeListener { buttonView, checkedId ->
    when (buttonView.id) {
        R.id.radioWhite -> {
            // ...
        }
        R.id.radioBlack -> {
            // ...
        }
    }
}

C

radioGroup.setOnClickListener {
    if (radioWhite.isChecked) {
        // ...
    } else if (radioBlack.isChecked) {
        // ...
    }
}

D

radioGroup.setOnClickListener {
    if (radioGroup.checkedRadioButtonId == R.id.radioWhite) {
        // ...
    } else if (radioGroup.checkedRadioButtonId == R.id.radioBlack) {
        // .
    }
}
Select one option from the list

Create a free account to access the full topic