Madona wambua
Madona wambua

Reputation: 1428

Stopping Score from Counting if user clicks twice

I am learning how to code this game and I have noticed that once the answer entered is correct one can click on the answer and still add on the score. I was wondering how can i make sure that the answer is only entered once? if the answer is true for someone to get 1 score?

if(answer == q.getAnswer()){
                    scoreTxt.setText("Score: "+(putScore+1));
                    correct = true;
}else if(answer != q.getAnswer()){

                setHighScore();
                scoreTxt.setText("Score: 0");

Upvotes: 1

Views: 32

Answers (2)

BVB
BVB

Reputation: 5430

There are several options. One example is disabling the button after it has been clicked in the OnClickListener:

button.setEnabled(false);

Don't forget to enable the button once moving on to the next question (I'm assuming your game has questions and answers).

Upvotes: 1

Atra Viator
Atra Viator

Reputation: 535

You're marking a bool as true. Why not use it to make sure the check can only succeed once?

if(answer == q.getAnswer() && !correct) {

Upvotes: 0

Related Questions