Raj
Raj

Reputation: 693

Track amount of clicks user clicks button

I was wandering if there was any way to track the amount of clicks a user clicks a button.

I am creating a game and the user will only be allowed to take 5 turns. After these turns the user has lost the game.

I need to create maybe an if statement where the amount of clicks the user takes reaches > 5 then the user has lost. Is this possible.

I appreciate any help on this. Thanks

Edit:

Button link2Btn = (Button)findViewById( R.id.answerSelected );

link2Btn.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { i++;

getAnswer(); }

The get Answer method works fine except the if i > 5 statement within get Answer which is:

else if(i>5){
    correctAnswer.setText("You have lost");

Upvotes: 0

Views: 331

Answers (1)

Tanmay Mandal
Tanmay Mandal

Reputation: 40198

Use a flag variable and make an increment over a button press. like

int i=0;

when button pressed

i++;

Now your condition

if(i>5){}

Upvotes: 1

Related Questions