Skip to content

Commit

Permalink
Updated JSONObject to JSONArray in Spinner Alias
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed May 6, 2019
1 parent 46e06b1 commit 66df34c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -691,17 +691,17 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
String openMrsEntityParent = (String) parent.getTag(R.id.openmrs_entity_parent);
String openMrsEntity = (String) parent.getTag(R.id.openmrs_entity);
String openMrsEntityId = (String) parent.getTag(R.id.openmrs_entity_id);
JSONObject jsonObject = (JSONObject) parent.getTag(R.id.alias);
JSONArray jsonArray = (JSONArray) parent.getTag(R.id.alias);
CustomTextView customTextView = (CustomTextView) parent.getTag(R.id.number_selector_textview);
Boolean popup = (Boolean) parent.getTag(R.id.extraPopup);
if (popup == null) {
popup = false;
}

String value = parent.getItemAtPosition(position).toString();
if(jsonObject != null && jsonObject.has(value)){
if(jsonArray != null && position >0 && jsonArray.length() > 0){
try {
value = jsonObject.getString(value);
value = jsonArray.getString(position);
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT));
}

JSONObject aliasJson = null;
JSONArray aliasJson = null;
if (jsonObject.has(JsonFormConstants.ALIAS)) {
aliasJson = jsonObject.getJSONObject(JsonFormConstants.ALIAS);
aliasJson = jsonObject.getJSONArray(JsonFormConstants.ALIAS);
spinner.setTag(R.id.alias, aliasJson);
}

Expand Down Expand Up @@ -139,7 +139,7 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
values[i] = valuesJson.optString(i);
if (aliasJson == null && valueToSelect.equals(values[i])) {
indexToSelect = i;
} else if (aliasJson != null && valueToSelect.equals(aliasJson.getString(values[i]))) {
} else if (aliasJson != null && valueToSelect.equals(aliasJson.optString(i))) {
indexToSelect = i;
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.6.1-SNAPSHOT
VERSION_NAME=1.6.3-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/assets/json.form/single_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@
"Ame OA",
"Haja OA"
],
"alias": {
"Ame OA": "Married",
"Haja OA": "Single"
},
"alias": [
"Married",
"Single"
],
"v_required": {
"value": "true",
"err": "Please enter the sex"
Expand Down

0 comments on commit 66df34c

Please sign in to comment.