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 i开发者_StackOverflow社区f(i>5){
correctAnswer.setText("You have lost");
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){}
精彩评论