1616import android .widget .LinearLayout ;
1717import android .widget .TextView ;
1818
19+ import org .apache .commons .lang3 .StringUtils ;
1920import org .redcross .openmapkit .R ;
2021import org .redcross .openmapkit .odkcollect .tag .ODKTag ;
2122import org .redcross .openmapkit .odkcollect .tag .ODKTagItem ;
2223
2324import java .util .Collection ;
25+ import java .util .HashSet ;
26+ import java .util .Set ;
2427
2528/**
2629 * A simple {@link Fragment} subclass.
@@ -80,15 +83,16 @@ private void setupCheckBoxes() {
8083 /**
8184 * Setting up buttons with prescribed choice values.
8285 */
83- String prevTagVal = tagEdit .getTagVal ();
84- boolean prevTagValInTagItems = false ;
86+ Set <String > prevTagVals = tagEdit .getTagVals ();
87+ // Used to keep track of the values not in ODKTagItems
88+ Set <String > prevTagValsNotInChoices = new HashSet <>(prevTagVals );
8589 Collection <ODKTagItem > odkTagItems = odkTag .getItems ();
8690 int id = 1 ;
8791 for (ODKTagItem item : odkTagItems ) {
8892 String label = item .getLabel ();
8993 String value = item .getValue ();
90- if (value . equals ( prevTagVal )) {
91- prevTagValInTagItems = true ;
94+ if (prevTagVals . contains ( value )) {
95+ prevTagValsNotInChoices . remove ( value ) ;
9296 }
9397 CheckBox checkBox = new CheckBox (activity );
9498 checkBox .setTextSize (18 );
@@ -103,7 +107,7 @@ private void setupCheckBoxes() {
103107 textView .setText ("" );
104108 }
105109 checkboxLinearLayout .addView (checkBox );
106- if (prevTagVal != null && value . equals ( prevTagVal )) {
110+ if (prevTagVals . size () > 0 && prevTagVals . contains ( value )) {
107111 checkBox .toggle ();
108112 }
109113 checkBox .setId (id );
@@ -115,8 +119,9 @@ private void setupCheckBoxes() {
115119 final CheckBox editTextCheckBox = new CheckBox (activity );
116120 final EditText editText = new EditText (activity );
117121 editText .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
118- if (!prevTagValInTagItems && prevTagVal != null ) {
119- editText .setText (prevTagVal );
122+ if (prevTagValsNotInChoices .size () > 0 ) {
123+ String joinedNotInChoices = StringUtils .join (prevTagValsNotInChoices , ";" );
124+ editText .setText (joinedNotInChoices );
120125 editTextCheckBox .setChecked (true );
121126 }
122127 editText .addTextChangedListener (new TextWatcher () {
0 commit comments