本文介绍了如何:跟踪调查表的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切顺利,我正在开发一个涉及片段,跟踪数据和SharedPreferences 的练习应用程序,在这种情况下,我有一个类似问卷的应用程序,它将询问用户15个问题,但在本示例中,我要说五(5),并使用带有是"和否"按钮的随机问题作为选项.它看起来像这样:

Good day all, I am working on a practice app that involves fragments, keeping track of data, and SharedPreferences, 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:

是/否

是/否

是/否

是/否

是/否

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

图1-显示应用程序的外观-线性布局均分成两部分

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

现在,每个问题都以其自己的Fragment-在此处显示的片段"中显示.如图1所示.下半部分的是"和否"按钮不应停滞,而是实际上与每个问题有关.一旦用户单击按钮上的选项,它将显示另一个问题.注意:这些问题不是列表,选择一个特定的(是/否)将依次显示相应的问题.

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.

例如,问题1:是将带您进入问题3,回答否将带您进入问题4,依此类推.现在,每个问题都可以选择或有机会给出文档或说您将需要document.doc".根据选择.我需要找到一种跟踪用户选择的答案的方法,在计算出这些答案以及显示文档的机会时,我将显示一个结果页面,告诉用户:您将需要以下文档:文档. doc,hello.doc等".结果页面显示所有用户选择的内容.例如

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.

推荐答案

如果我正确理解了您的问题的核心,那么您(针对每个问题)的活动和观点(必须针对每个问题)需要整合为一个中心状态,并收集所有答案和他们确定的文件.因此,解决方案的想法是拥有一个域对象,该对象包含答案以及从给定答案中确定文档的逻辑.像

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:

  • 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. Lifetime of a static variable in Android.

另一种方法是在应用程序中保留该类的一个对象(Application类的扩展).为确保应用程序换出时答案值不会丢失,每个活动应在其onSaveInstanceState方法中调用对序列化答案的Questionnaire方法,并反过来在其onCreate方法.

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.

从用户的角度来看,豪华版是将答案存储在数据库中,在那里,除了设备的物理破坏外,它们将在所有情况下幸免于难.

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.

哪种方式还取决于使用情况.如果您使用户形象地回答所有这些问题而不会打扰,则可能不需要保存实例.用户在调查表中投入的精力越多,您的应用就应该花更多的精力来保持答案.

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.

这篇关于如何:跟踪调查表的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:48
查看更多