title: How to get the text from the Button when clicked?
body: <pre><code>for( i=0; i&lt;26; i++)    {
      
      btnAlpha[i] = new Button(this);
      btnAlpha[i].setBackgroundColor(Color.TRANSPARENT);
      btnAlpha[i].setTextColor(Color.GREEN);
      btnAlpha[i].setText(Character.toString ((char)(j+i)));
      btnAlpha[i].setOnClickListener(new View.OnClickListener(){              
          public void onClick(View v){
          //Want to get the text from the current button.
                           btnAlpha[i].getText();
                          //But it gives error that &quot;i&quot; cannot be accessed.
              
      }});
  </code></pre>
  <p>I get the error &quot;cannot refer to a non-final variable inside an inner class defined in a different method&quot;. But I need to get the text at that right time. How to do it? Is there any other way to do it?</p>