Single-selection logic for multiple, interconnected checkboxes

Source: Internet
Author: User

CheckBox of the State logic, the state of a good time to write well, when the state is not good to debug for a long time, of course, mainly on the event is not very clear.

Give it first.

  

And then give the code,

  

Selectzhifubaopay.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {if(selectweixinpay.ischecked ()) {if(selectzhifubaopay.ischecked ()) {selectweixinpay.setchecked (false); Pay_mode=ALIPAY; } Else{Pay_mode=Tenpay; }                } Else{                    if(selectzhifubaopay.ischecked ()) {Pay_mode=ALIPAY; } Else{Pay_mode= "";        }                }                            }        }); Selectweixinpay.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {if(selectzhifubaopay.ischecked ()) {if(selectweixinpay.ischecked ()) {selectzhifubaopay.setchecked (false); Pay_mode=Tenpay; } Else{Pay_mode=ALIPAY; }                } Else{                    if(selectweixinpay.ischecked ()) {Pay_mode=Tenpay; } Else{Pay_mode= ""; }                }            }        });

CheckBox Image Effect Transform event we put in the XML file, mainly a button property settings, in the drawable set the click and not click on the background map is OK, this can reduce the code's judgment.

From the result of the debug, the check state of the checkbox has changed before responding to the Click event, then executes the event in the onclick, then executes the setchecked in the onclick and does not execute the event in the onclick. is to not execute the logic of the code we write ourselves.

This is a non-Gan Lian. Two checkboxes to establish a single-selection relationship, if the checkbox inside the ListView is to establish a single-selection relationship, consider storing the state information in an array list, and each time the execution of the state information is judged to be true.

  

Single-selection logic for multiple, interconnected checkboxes

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.