【发布时间】:2014-02-28 19:21:30
【问题描述】:
我已经使用以下代码创建了动态按钮,我想听听它们。创建的按钮数量未定义,因为变量 drawView.getNumeroMallas() 是一个动态数字,并且每次都可以更改。 当我听它们时,我需要知道每个按钮的每个索引“i”。如何动态实现 onClickListener?谢谢。
LinearLayout buttonsLayout = (LinearLayout)findViewById(R.id.linearlayoutUp);
for(int i=0;i<drawView.getNumeroMallas();i++){
Button buttonMalla = new Button(this);
Button buttonRotar = new Button(this);
buttonMalla.setText("Malla "+(i+1));
buttonsLayout.addView(buttonMalla);
buttonsLayout.addView(buttonRotar);
}
【问题讨论】: