I’m trying to make a small Android game. My on click function however is not getting repeated… It adds one point the first time and then stops working. It looks correct to me.
addButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
playerScoreField = (TextView)findViewById(R.id.playerScore);
int playerScore = 0;
if(playerScore != target){
playerScore++;
playerScoreField.setText("You are at: " + playerScore);
} else {
addButton.setClickable(false);
addButton.setEnabled(false);
countDown.onFinish();
}
}
});
I think you might have a logic error. You are setting playerScore to zero on each click. This will result in the score always being 1. Declare your playerScore variable in a different way.