jeudi 16 juin 2016

How to get the values of multiple checkboxes and send values to server in android

I`m working to a program in Android Studio. I try to get the values from multiple checkboxes (35) and put them to json for sending to server. Here is the SetMethod to get the selected values of checkboxes:

private void setExtensionForwardNumber(){

            priorityResponse.priorityOne.getTimeTable().mon = verifyCheckbox(priorityOneMon);
            priorityResponse.priorityOne.getTimeTable().tue = verifyCheckbox(priorityOneTue);
            priorityResponse.priorityOne.getTimeTable().wed = verifyCheckbox(priorityOneWed);
            priorityResponse.priorityOne.getTimeTable().thu = verifyCheckbox(priorityOneThur);
            priorityResponse.priorityOne.getTimeTable().fri = verifyCheckbox(priorityOneFri);
            priorityResponse.priorityOne.getTimeTable().sat = verifyCheckbox(priorityOneFri);
            priorityResponse.priorityOne.getTimeTable().sun = verifyCheckbox(priorityOneSun);

String s = priorityResponse.toJsonObject();

    setForwardExternalFragment(s);

}

Here is the function that verify is checkbox is checked or not:

private boolean verifyCheckbox(CheckBox checkbox) {

boolean selected = checkbox.isChecked();

if(selected)
    checkbox.setChecked(true);
else
checkbox.setChecked(false);
return selected;

}

I tried to not use function verifyCheckbox, and i use checkbox.isChecked(), but I get the same result

priorityResponse.priorityOne.getTimeTable().tue = priorityOneTue.isChecked();

The problem is when I receive the value on the server, i get mixed values. Example: If i check mon,wed,fri,sun, on the server the selected values are: mon,tue,wed,thu,sun.
Where did I go wrong?

Thank you!




Aucun commentaire:

Enregistrer un commentaire