Ejemplo n.º 1
0
  // Method will be called when a button is clicked to answer a question.
  // It will grey out all the answers except the correct one, which will be in green
  // if the user selected the wrong answer, it will be shown in red.
  public void checkAnswer(View v) {

    buttons[0] = (Button) findViewById(R.id.button1);
    buttons[1] = (Button) findViewById(R.id.button2);
    buttons[2] = (Button) findViewById(R.id.button3);
    buttons[3] = (Button) findViewById(R.id.button4);

    Button btnChosen = (Button) findViewById(v.getId());
    TextView scoreView = (TextView) findViewById(R.id.evScore);

    /* can change getText to getKey and set a key in the xml*/

    // checks the buttons text against the Question
    boolean correct = currentQuestion.checkAnswer(btnChosen);

    if (correct) {
      btnChosen.setBackgroundColor(Color.GREEN);
      score++;
      scoreView.setText(Integer.toString(score));
      btnChosen.setEnabled(false);

    } else btnChosen.setBackgroundColor(Color.RED);

    for (int i = 0; i < 4; i++) {
      if (btnChosen.equals(buttons[i])) continue;

      if (currentQuestion.checkAnswer(buttons[i])) buttons[i].setBackgroundColor(Color.GREEN);
      else buttons[i].setBackgroundColor(Color.GRAY);
      buttons[i].setEnabled(false);
    }

    // savedInstanceState.putInt(KEY_SCORE, score);

  }
Ejemplo n.º 2
0
  public void findCorrect(Button btnSkip) {

    // finds the correct answer and makes it green all others are gray
    for (int i = 0; i < 4; i++) {
      if (btnSkip.equals(buttons[i])) continue;

      if (currentQuestion.checkAnswer(buttons[i])) buttons[i].setBackgroundColor(Color.GREEN);
      else buttons[i].setBackgroundColor(Color.GRAY);
    }
  }