I want to incease the integer if the checkbox is check, and descrease if it isn't. My try:
a = 0
checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
a++;
} else {
a--;
}
}
});
checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
a++;
} else {
a--;
}
}
});
if (a == 1){
CompoundButtonCompat.setButtonTintList(checkbox1, ColorStateList.valueOf(context.getResources().getColor(R.color.red)));
CompoundButtonCompat.setButtonTintList(chechbox2, ColorStateList.valueOf(context.getResources().getColor(R.color.red)));
}
if (a == 2) {
CompoundButtonCompat.setButtonTintList(chechbox1, ColorStateList.valueOf(context.getResources().getColor(R.color.orange)));
CompoundButtonCompat.setButtonTintList(checkbox2, ColorStateList.valueOf(context.getResources().getColor(R.color.orange)));
}
I don't know, maybe integer doesn't increase - descrease, or I can't access the integer. What should I do?
Aucun commentaire:
Enregistrer un commentaire