为(I = 0;我< 26;我++){Android:单击按钮时如何从按钮中获取文本?
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 "i" cannot be accessed.
}});
错误我得到的是 “不能指非最终变量在不同的方法中定义的内部类内侧”。但我需要在适当的时候获得文本。怎么做?有没有其他方法可以做到这一点? 请帮忙!
非常感谢!这解决了这个问题。 – GamDroid 2010-11-05 15:38:59