I'm working on creating an application, which amongst other features has an integrated GAD Test functionality (self test to calculate and measure the user's stress level). This is how it looks:
It is consisted of a Table, with multiple rows of ToggleButtons. This is the code for 1 of the buttons, as an example:
<ToggleButton
android:id="@+id/row1_btn4"
android:layout_width="200px"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/button_border"
android:gravity="center"
android:paddingStart="10px"
android:paddingEnd="10px"
android:scaleX="0.5"
android:scaleY="0.65"
android:textColor="@color/white"
android:textOff=" "
android:textOn="✓"
android:textSize="28sp" />
and this is the code to check whether a button is checked or not:
row1_btn4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
gadpoints += 3;
((DataSite) getActivity().getApplication()).setGadPoints(gadpoints);
} else if (!isChecked) {
gadpoints -= 3;
((DataSite) getActivity().getApplication()).setGadPoints(gadpoints);
} else {
gadpoints += 0;
((DataSite) getActivity().getApplication()).setGadPoints(gadpoints);
}
}
});
Everything is working as it should, if a ToggleButton is checked, the user is awarded the given points. However, I would like to implement 2 things:
a) Make it so that only 1 button from each row can be checked, and prevent the user from checking another one from the same row if he / she already checked 1
b) Check whether in a row of buttons none of them has been checked, and if so, notify the user
I cannot think of a feasible solution to this, because I will be essentially checking if a button hasn't been checked, but then again, some of them are meant to be unchecked. Any ideas?