小编use*_*217的帖子

onClickListener动态ANDROID

我用跟随代码创建了动态按钮,我想听听它们.创建的按钮数量是未定义的,因为变量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);
        }
Run Code Online (Sandbox Code Playgroud)

android onclick button

0
推荐指数
1
解决办法
84
查看次数

标签 统计

android ×1

button ×1

onclick ×1