Delivering Surveys

What Is a Survey?

A Survey is a Java class that represents a survey with questions and answers. Questions are in text format while answers can be inputted via text, radio buttons, or check lists.

A question and an answer make up a survey node (SurveyNode). As can be seen in Figure 1, a SurveyNode contains of a Question and an Answer.  A collection of survey nodes make up an entire survey. Our library can represent these nodes and render them on screen as the telemonitoring node. Custom question and answer formats can also be created by extending the classes.

Question, Answer, Node

Figure 1. Illustration of the hierarchy of questions, answers and survey nodes.

How to Create a Survey?

The following question and answer types are supported in the framework.


TextQuestion: An object of this class represents a question that consists only from text.


TextAnswer: An object of this class represents an answer that allows users to input their answers as text.
CheckListAnswer: An object of this class represents an answer of multiple choices (check list)
RadioListAnswer: An object of this class represents an answer that allows one of many possible choices (radio buttons)

Initializing a Survey

These components can be used to build a survey as follows:

TextItemDescription Example

Figure 2. Illustration of the location of the TextItemDescription for a TextQuestion.


A question object always has a description and a value. The description is usually the text of the question, as shown in Figure 2. The value can be used for an ID number or other useful information.

TextItemValue Example

Figure 3. Illustration of the location of the TextItemValue for a TextAnswer.


An answer object also has a description and a value. The value is usually the user inputted text and the description is just a description of the answer. This can be seen in Figure 3.  For TextAnswer, the description is not shown on the screen.

The node is created with the question and the answer. Then it’s added to the list of nodes that the Survey contains.

Instead of TextAnswer as shown above, we can have RadioListAnswer or CheckListAnswer:

For answers that contain a list of options, we use the SelectableAnswer object to create the individual options.


Radio List Example

Figure 4. A complete SurveyNode with RadioListAnswer.


Now you can use the CheckListAnswer or RadioListAnswer to create a SurveyNode similar to the one in Figure 4.  A CheckListAnswer would have a similar appearance but would allow users to select multiple answers rather than just one.







How to Render a Survey?

Creating Survey Basics

Survey Basics

Figure 5. Illustration of the survey navigation buttons.

We defined a basic survey as having a next button, previous button, and submit button.  You can find the basic XML to create the survey layout in Figure 5 with appropriate onClick listeners set for the buttons below.


Converting Survey to be Renderable on the Phone

To render the survey, we must first convert it to a renderable type.

We must then render the initial question when the user first accesses the survey.

To do this, call the render method of the first SurveyNode in the onCreate method of your activity to get the fragment with the first question and answer. Then display that fragment with FragmentManager.

Navigating through the Questions

We must define the onClick methods for buttons as specified in the XML to define behavior when the user clicks on the next, previous, and submit survey buttons.

When the previous or next button is pressed, currentIndex must be incremented or decremented accordingly.

Now we can replace the current fragment with the fragment of the new index.

Sending Survey Back to the Server

Before the survey (of type SurveyRenderer) is submitted, it must be converted back to a Survey.  This is because an object of type Survey can be handled by the server while an object of type SurveyRenderer cannot.


Advanced: How to Create Custom Questions and Answers?

 Implementing New Question and Answer Types

  1. Create your new class that implements the QuestionInterface or AnswerInterface in the Core library
  2. Create a corresponding renderer class that implements QuestionRendererInterface or AnswerRendererInterface in the Client library
  3. Create a corresponding class in the Client library that extends Fragment and override the onCreateView method for custom display of your Question/Answer type
  4. Extend the SurveyConverter class to add conversions between your class that implements QuestionInterface/AnswerInterface and your class that implements QuestionRendererInterface/AnswerRendererInterface.  Pass in an instance of your custom converter class when creating the Survey object.

Running Example

(TODO: complete)