title: How to increment a Counter inside an OnClick View Event
body: <p>I know this might sound very basic but here's my problem:</p>
  
  <p>I have an onclickevent listener that's supposed to increment the counter indefinitely when it's clicked:</p>
  
  <pre><code>final int counter = 0;
  myimageView2.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
          counter ++;
      }
  });
  </code></pre>
  
  <p>The problem is that I can't seem to call the counter from inside the onclick event unless it's set to <strong>final</strong>. However since it's final I can no longer change its value either.</p>
  
  <p>I tried placing the counter within the onclick event, i.e.:</p>
  
  <pre><code>myimageView2.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
          int counter = 0;
          counter ++;
      }
  });
  </code></pre>
  
  <p>However, clicking it also resets the counter back to zero.</p>
  
  <p>How do I solve this? I want to continuously increment the counter each time I click it,
  but I can't define the counter outside of the onclick unless it's final, which means I can no longer increment it. And I can't define the counter inside the onclick either since it will only reset its value each time I click it.</p>