We are currently working on project where a web user creates a survey which has cascading questions (cascading means questions that have few answers and depend on those answers rest of the questions changes) and then mobile users should get this survey in their android app. Sample JSON
structure we thought is as follows:
{
"status": "1",
"tabs": [
"Farmer Information",
"Signature",
"Crop Details",
"Land Parcel"
],
"survey":[
{
"type": "TextView",
"cascade": "0",
"value": "What is your name?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "What is your age?",
"survey" : ""
},
{
"type": "RadioButtonGroup",
"cascade": "1",
"value": "Do you have kids?",
"survey" : [
{
"type": "TextView",
"cascade": "1",
"value": "YES",
"survey": [
{
"type": "TextView",
"cascade": "1",
"value": "How many of them below 18?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How many of them are girls?",
"survey" : ""
},
{
"type": "TextView",
"cascade": "1",
"value": "Where do you live in?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How long you were there?",
"survey" : ""
}
]
},
{
"type": "TextView",
"cascade": "0",
"value": "NO",
"survey" : [
{
"type": "TextView",
"cascade": "1",
"value": "Where do you live in?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How long you were there?",
"survey" : ""
}
]
}
]
}
]
}
Is there anyway to achieve such a thing? What are the most suitable library which can be used for this scenario? We tried json2view, proteus. From all those we can pass a json and load the view but if there are cascading questions non of them can use.
Furthermore elaborating in the question via an example:
Suppose the user is given the question of Do you have any have kids?
. This question has possible two answers. Yes
& No
depending upon the answer which user give others questions have to be loaded dynamically.
This may be too late, but here goes. This can be done in
proteus
.By creating a custom view, let call it
SurveyView
which has 3 custom attributesstatus
: initial conditioncascade
: the check conditionsurvey
: array of childSurveyView
So, in Native Android, there would be a method
setStatus()
which will be called when an answer is selected. This will set thestatus
of the child survey views. The child will check the newstatus
against the condition set on them. If it matches, it isvisible
elsegone
.After this simply register this as a custom view with proteus. There is a slightly more complicated way of doing this without a custom view (by using function bindings in like so.
Where
data.status
is the status propagated down from the parent and0
is the cascade condition. You get the drift.You can create and register your own custom functions too.
P.S. why not react native?
P.P.S Use
proteus
tag in questions related to proteus, this is why I missed this.