Reputation: 159
I'm working on creating an application with Java. In one of the screens, I've got 4 checkboxes, where if they are checked, the user is awarded with 15 points, and if they are not, no points are given. I've got the following code to check whether the ToggleButton is checked or not (taken from the Android Developers documentation):
fg_reflect_checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
reflectpoints += 15;
((DataSite) getActivity().getApplication()).setReflectPoints(reflectpoints);
} else {
reflectpoints += 0;
((DataSite) getActivity().getApplication()).setReflectPoints(reflectpoints);
}
}
});
This works just fine, if I tap on the toggle, a tick is added, and I am awarded with 15 points. However, if I tap it again to remove the tick, and then tap it back on to add it again, it adds 15 more points, totaling to 30.
This is a problem for me, since a user can accidentally tap on a toggle to remove the tick, and then tap it again to correct his / her mistake. He / she will not be awarded 15 points, but 30.
I've tried implementing a second check within the if clause but it didn't work. I would essentially like to check if the tick is there, and avoid the score being registered twice, or more times with every tap. Any ideas?
Upvotes: 0
Views: 46