I have a form that has multiple checkboxes. Each checkbox is worth a different amount 1-5,] See values in brackets in screenshot. I need to get the result of all the clicked checkboxes and add them up. Ive seem multiple ways of doing this but what is the best. If statements and switch statements seem too long. Ive seen array lists but i have three sections on the form so could I do three seperate array lists for each one and then add the values in the array?
XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackground">
<com.google.android.material.card.MaterialCardView
android:id="@+id/redflag_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="32dp"
android:layout_marginRight="8dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Media -->
<!-- Buttons -->
<ImageView
android:layout_width="match_parent"
android:layout_height="184dp"
android:background="#FFFFFF"
android:contentDescription="orange_flag"
app:srcCompat="@drawable/secondary_symptoms" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/gcs_test"
android:layout_width="match_parent"
android:layout_height="320dp"
android:orientation="vertical"
android:padding="16dp">
<!-- Title, secondary and supporting text -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gcs_title"
android:textAppearance="?attr/textAppearanceHeadline6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/gcs_intro"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
android:textSize="16sp" />
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/eye_heading"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
android:textSize="16sp" />
<CheckBox
android:id="@+id/cb_eye_response1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eye_check1" />
<CheckBox
android:id="@+id/cb_eye_response2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/eye_check2" />
<CheckBox
android:id="@+id/cb_eye_response3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/eye_check3" />
<CheckBox
android:id="@+id/cb_eye_response4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/eye_check4" />
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/verbal_heading"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
android:textSize="16sp" />
<CheckBox
android:id="@+id/cb_verbal_response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/verbal_check_1" />
<CheckBox
android:id="@+id/cb_verbal_response2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/verbal_check_2" />
<CheckBox
android:id="@+id/cb_verbal_response3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/verbal_check_3" />
<CheckBox
android:id="@+id/cb_verbal_response4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/verbal_check4" />
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/motor_heading"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
android:textSize="16sp" />
<CheckBox
android:id="@+id/cb_motor_response1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/motor_check_1" />
<CheckBox
android:id="@+id/cb_motor_response2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/motor_check_2" />
<CheckBox
android:id="@+id/cb_motor_response3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/motor_check_3" />
<CheckBox
android:id="@+id/cb_motor_response4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/motor_check4" />
<CheckBox
android:id="@+id/cb_motor_response5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/motor_check5" />
<CheckBox
android:id="@+id/cb_motor_response6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/motor_check6" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/gc_score_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="updateScore"
android:text="@string/gcs_score" />
<EditText
android:id="@+id/gcs_score_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="12dp"
android:textSize="22sp"
android:autofillHints=""
android:layout_marginStart="12dp" />
</LinearLayout>
<TextView
android:id="@+id/gcs_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#F10E3C"
android:text="@string/gcs_result_text"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
<!--App designed Buttons to continue/call ambulance -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/gcs_call_ambulance"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:onClick="onButtonClicked"
android:text="@string/call_ambulance" />
<com.google.android.material.button.MaterialButton
android:id="@+id/gcs_continue"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClicked"
android:text="@string/continue_diagnosis" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</ScrollView>
Aucun commentaire:
Enregistrer un commentaire