Android automatically calls OnCheckedChanged when the ListView Scrolls

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.