title: Using a loop to set the buttons onclicklistener
body: <p>I am trying to use a loop to set the action for each button when clicked (since most of the buttons will just return their text value), however I am getting an error stating "variable 'i' is accessed from within inner class, needs to be declared final". How can I get around this? </p>
  
  <p>Here is what I got</p>
  
  <pre><code>String getValuesPressed(){
  
      for(int i = 0; i &lt; buttonList.length; i++){
  
          buttonList[i].setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if(i == 0){//error occurs here
                      //do stuff
                  }
  
              }
          });
      }
      return textOnScreen;
  }
  </code></pre>