-1
nome_adc_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double percent = (estimatedFare*0.20);
double soma = estimatedFare + percent;
double subtrai = estimatedFare - percent;
if (nome_adc_1.isChecked()) {
estimatedFare = soma;
} else {
estimatedFare = subtrai;
}
tvEstimatedFare.setText(getNewNumberFormat(estimatedFare));
}
});
The above code I use for a checkbox. When the checkbox is clicked, it takes the value of the estimatedFare and adds 20%. works perfectly. The problem is that when unchecked, the subtraction it makes is different, the value decreases by about 0.25 of the total value. That is, if you keep checking and unchecking the checkbox, the value shown goes to zero. someone knows the reason?
That’s exactly what’s happening! instead of subtracting the percentage of the estimatedFare it is subtracting the percentage of the estimatedFare after +=.
– brunomassoni