Esempio n. 1
0
  /**
   * Change the view after user clicks the next button If all the questions are answered, store the
   * results and return to the main activity
   *
   * @param v
   */
  public void nextButtonOnClick(View v) {
    // Store the result of the current view(question)
    try {
      saveResult();
    } catch (IllegalArgumentException ex) {
      Toast.makeText(getApplicationContext(), "Please pick an answer", 300).show();
      return;
    }

    // Save the results into the database and exit this activity
    if (currentView == viewSize) {
      // Save results into the database
      for (int i = 0; i < viewTypeArray.length; i++) {
        for (int j = 0; j < resultList[i].size(); j++) {
          dataSource.storeAnswer(
              i + 1,
              questionTextArray[i],
              viewTypeArray[i].toString(),
              (Integer) resultList[i].get(j));
        }
      }

      // Set alarm for notification
      setNotifiAlarm();

      // Return to the main activity/screen
      dataSource.close();
      finish();
      Intent intent = new Intent(this, HealthyDroidActivity.class);
      startActivity(intent);
    }

    currentView++;

    if (currentView <= viewList.size()) {
      // Display the current question number
      TextView curQuestText = (TextView) findViewById(R.id.quiz_curQuestNumText);
      curQuestText.setText(currentView + "/" + viewSize);

      // Show the back button
      Button backButton = (Button) findViewById(R.id.quiz_backButton);
      backButton.setVisibility(View.VISIBLE);

      // If the current question is the last question, set the next button
      // to display "Finish"
      if (currentView == viewSize) {
        Button nextButton = (Button) findViewById(R.id.quiz_nextButton);
        nextButton.setText("Finish");
      }
      // Add slide out animation to the previous question
      if (currentView >= 2)
        viewList
            .get(currentView - 2)
            .setAnimation(
                AnimationUtils.loadAnimation(
                    this.getBaseContext(), R.anim.view_transition_out_left));

      lLayout.removeAllViews();
      // Add slide in animation to the current question
      viewList
          .get(currentView - 1)
          .setAnimation(
              AnimationUtils.loadAnimation(this.getBaseContext(), R.anim.view_transition_in_left));
      lLayout.addView(viewList.get(currentView - 1));
      return;
    }
  }