Reputation: 171
I'm currently learning Android development from a book and I've come to the topic of radio buttons. The book explains that you handle radio button clicks (within a RadioGroup) using setOnCheckedChangeListener()
with an anonymous OnCheckedChangeListener
class as an argument.
However, according to the Android documentation you can set the onClick
attribute on radio buttons to simply refer to a method of your design and handle clicks there.
Is there a reason to choose one over the other? What I'm asking is if there is some difference between the two that I'm missing, or if they simply both do the same thing.
Upvotes: 1
Views: 45
Reputation: 1009
setOnCheckedChangeListener()
is listening to checked state, so if it is changed programmatically your code will be triggered. onClick
listener only detects changes on checked state only if the element is clicked.
Upvotes: 1