82842

How to: Keep track of Progress on questionnaire

Question:

Good day all, I am working on a practice app that involves <em>fragments, keeping track of data, and SharedPreferences</em>, Here is the scenario, I have a questionnaire-like app, it will ask the user 15 questions but for the sake of this example i'm going to say five(5) and use random questions with yes and no buttons as options.It will look something like this:

<h3>|Question 1: Are you a citizen?|</h3>

yes/no

<h3>|Question 2: Are you human?|</h3>

yes/no

<h3>|Question 3: Do you sleep a lot?|</h3>

yes/no

<h3>|Question 4: Do you think you will need help?|</h3>

yes/no

<h3>|Question 5: Do you often say bye?|</h3>

yes/no

|----------------------------| | | | | | | | fragment displayed here | | | | | |----------------------------| | | |yes no | |----------------------------|

figure 1- Shows how the app looks-both linear layouts split into two

Now, each question is in its own Fragment-displayed in the "fragments displayed here" section seen in figure 1. The yes and no buttons in the bottom half are NOT supposed to be stagnant but in fact connected to each question. Once the user clicks an option from the buttons, it will display another question. Note: The questions are not a list, the selection of a particular (yes/no) will in turn display the corresponding question.

So for example, Question1:yes will take you to Question3, answering no will take you to Question 4 and so on. Now, each question has the option or chance to give a document or say "You will need document.doc" based on the selection. I need to find a way to keep track of what answers the user picked, and upon calculating those answers along with the chance of displaying a document i will show a results page telling the user: "You will need the following documents: documents.doc, hello.doc etc". The results page shows what all the user chose. e.g

Question1:yes Question2:no Question3:yes Question4:yes Question5:yes Result: You will need documents: documents.doc, hello.doc, bye.doc, yes.txt

If anything is not clear, please let me know. Basically now all I want to know is how i can accomplish this task, i would really appreciate it if someone would work with me on getting this done as soon as possible. Thanks SO much in advance to the community.

Answer1:

If I get the core of your problem right, your have different activities and views (for each question) that need to be consolidated to a central state, collecting all answers and the documents determined by them. So the solution idea is to have a domain object that holds the answers and the logic to determine documents from given answers. Something like

class Questionnaire { private boolean answer1; private boolean answer2; ... public boolean setAnswer1(boolean answer) ... ... public String getNeededDocuments() { // determine documents from values of answer1, answer2, ... } }

There are several ways to implement this:

<ul><li>

The easiest way would be to make all attributes and methods of the class shown above static. But it may happen that those values get lost, cf. <a href="https://stackoverflow.com/questions/17900456/lifetime-of-a-static-variable-in-android" rel="nofollow">Lifetime of a static variable in Android</a>.

</li> <li>

Another way is to hold one object of the class in your application (extension of the Application class). To make sure the answer values don't get lost when the app is swapped out, each activity should, in its onSaveInstanceState method call a method of Questionnaire that serializes the answers, and conversely a call to deserialized them in its onCreate method.

</li> <li>

The luxury version from the user's point of view would be to store the answers in a database where they'll survive everything but physical destruction of the device.

</li> </ul>

Which way to go will also depend on the usage scenario. If you image the user to answer all those questions without interruption, saving instances might be unneeded. The more effort the user will put into that questionnaire, the more effort your app should take to persist the answers.

Recommend

  • How can I break selecting when condition is false?
  • Struct Not Used
  • get date from datetime in linq and show gridview [duplicate]
  • Custom headers per request in RestKit
  • how to display json data using ng-repeat?
  • What is the difference between scala classes, scripts and worksheets in Intellij-idea?
  • Find cluster in Neo4j
  • timelinechart couldn't decode Array as JSON:
  • To Unit Test or not to Unit test this part
  • Accessing MVC DI Service inside other services
  • ScraperWiki: How to create and add records with autoincrement key
  • ActionBar three-dot dropdown opens at the wrong place
  • How to run .ear file in JBoss 6?
  • How can I manually set the document id in a corpus?
  • jQuery Mobile - Dialogs without changing hash
  • Insert records if not exist SQL Server 2005
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • I18n locale disregarding fallbacks
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Sequential (transactional) API calls in angular 4 with state management
  • How to define and use opencv mat of user type
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Use of this Javascript
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Extracting HTML between tags
  • C++ Partial template specialization - design simplification
  • Linq Objects Group By & Sum
  • Optimizing database types to compact database (SQLite)
  • JSON with duplicate key names losing information when parsed
  • vba code to select only visible cells in specific column except heading
  • Change an a tag attribute in JavaScript based on screen width
  • How to get next/previous record number?
  • Python: how to group similar lists together in a list of lists?
  • Buffer size for converting unsigned long to string
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • reshape alternating columns in less time and using less memory
  • How can i traverse a binary tree from right to left in java?
  • How to Embed XSL into XML