Today, when I was doing a ListView with a checkbox, I found that when the state of the checkbox was initialized, the ListView was scrolled, where the checkbox's selected state changed continuously. The last reason to find out is that oncheckedchanged is automatically called when the ListView Scrolls. After reviewing the various blog solutions, there is a way to solve my problem on the foreign website. Write it down and share it.
This is done in the custom adapter GetView method.
Set the state change listener event to null Holder.checkBox.setOnCheckedChangeListener (NULL) before initializing the CheckBox state and setting the state Change listener event; Then set the checkbox state if (isChecked) { holder.checkbox.setChecked (true); } else { Holder.checkbox.setChecked (FALSE); } Then set the state Change listener event Holder.checkBox.setOnCheckedChangeListener (new Compoundbutton.oncheckedchangelistener () { @Override public void OnCheckedChanged (Compoundbutton buttonview, Boolean isChecked) { if (isChecked) { //... } else{ //...}} );
SOURCE Download: http://code.662p.com/list/11_1.html
Android automatically calls OnCheckedChanged when the ListView Scrolls