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