I have some trouble with setting a checkbox to be unchecked. I have two fragments, first fragment contains a checkbox and a button, after I check the check box and press the next button, second fragments loads and displays a message. When I press back button, the first fragment reloads and the checkbox remains checked, how can I make it to be unchecked.
Here's how I initialize the checkbox, this function is called from onViewCreated()
private void initRefundCheckBox(){
final CheckBox refund = getView().findViewById(R.id.refund_checkbox);
if(isRefund)//This section is to check if we reloaded the first
//pragment and isRefund was already true - then set it
//to be false and uncheck the checkbox
{
isRefund = false;
refund.toggle();
refund.setSelected(isRefund);
refund.setChecked(isRefund);
}
refund.setChecked(isRefund);
refund.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isRefund = refund.isChecked();
/// somecode
}
});
}