Esempio n. 1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quiz);

    // Open the database
    dataSource = new QuestionDataSource(this);
    dataSource.open();

    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    viewList = new ArrayList<LinearLayout>(0);

    HealthismQuiz quiz = QuizFactory.build(getResources().openRawResource(R.raw.quiz));

    viewSize = quiz.numQuestions();
    resultList = new ArrayList[viewSize];
    viewTypeArray = new QuestionType[viewSize];
    questionTextArray = new String[viewSize];

    // Load the views for the quiz and populate the database with options in every question
    for (int i = 0; i < viewSize; i++) {
      Question q = quiz.getQuestion(i);
      loadQuiz(q.getType(), q.getText(), q.getOptions().iterator());
      questionTextArray[i] = q.getText();
      viewTypeArray[i] = q.getType();

      // Store all the options for each question into the database
      ListIterator<String> optionsIt = q.getOptions().listIterator();
      while (optionsIt.hasNext()) {
        dataSource.storeOption(i, optionsIt.next());
      }
    }

    // Display the first question of the quiz
    initFirstQuestion();

    // Call the nextButtonOnClick method when the next button is clicked
    Button next = (Button) findViewById(R.id.quiz_nextButton);
    next.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            nextButtonOnClick(v);
          }
        });

    // Call the backButtonOnClick method when the back button is clicked
    Button back = (Button) findViewById(R.id.quiz_backButton);
    back.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            backButtonOnClick(v);
          }
        });
  }