The counter variable cannot be referred to in the public void onClick(View v) method, since it is defined in a different method. Below is the relevant code.
    Button button;
    final TextView message;
    int counter = 0;
    button = (Button) findViewById(R.id.button5);
    message = (TextView) findViewById(R.id.tv5);
    message.setText("Clicked " + 0 + " times.");
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            counter++;
            message.setText("Clicked " + counter + " times.");
        }
    });
Are there any ideas as to how to fix this?
The reason I do not want to declare counter as a final variable is because I still want to change its value in the Onclick method.
Thank you.
 
    