Java – oncheckedchangelistener or onclicklistener with if statement for checkbox? What’s the difference between functions?

Hello, I'm creating an Android application that uses checkboxes. I want to know if onchecked changelister is better used to perform some operations when the status of the checkboxes changes, or if it's better to use onclicklistener with an internal if statement to execute it every time the check box is selected or deselected? thank you

Solution

With onchecked changelister, you will receive an event whenever the check status changes, even when using The same is true when setchecked () completes the code

Depending on what you are doing, this can lead to unexpected behavior (for example, when you have a check box in the list view, the view is recycled and the check box status is programmatically modified, which looks exactly the same as the way the user clicks it)

Therefore, when you write code that should respond to the user who clicks the check box, you should use onclicklistener

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>