I have a RadioGroup with dynamically added RadioButtons. In my Activity, I close the activity immediately after a RadioButton is selected. However, this leads to an artifact where two RadioButtons look like they are selected before the Activity finishes. The previous selection and current selection are both still animating when the Activity finishes.
Is there a way to speed up the animation or disable it altogether so that I don't see this visual artifact?
radioButton.setChecked(true); // previous selected button is still deselecting and current button is now selecting. both are in the middle of animating but activity closes before they can finish animating
finishWithResult(selected == null ? Activity.RESULT_CANCELED : Activity.RESULT_OK, selectedItem);
In order to allow the user to see the selection of the RadioButton they've selected you can delay closing the Activity instead of turning off the RadioButton selection animation.
radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
Handler(Looper.getMainLooper()).postDelayed(
{
finish()
},
500
)
}
If you would like to remove the animation regardless, you can see the answer here: https://stackoverflow.com/a/51411238/1212331
E.g.
radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
radioGroup.jumpDrawablesToCurrentState()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With