Dynamically creating Buttons and setting onClickListener

后端 未结 9 996
囚心锁ツ
囚心锁ツ 2020-11-29 22:45

I have problem with handling dynamically created Buttons on Android. I\'m creating N buttons and I have to do the same method when button is clicked but I have to know which

9条回答
  •  -上瘾入骨i
    2020-11-29 22:57

    public class MainActivity extends Activity implements View.OnClickListener
    {
    
    LinearLayout linearLayout;
    Button [] button;
    View.OnClickListener listener;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        linearLayout=(LinearLayout)findViewById(R.id.parent_lay);
        String[] array={"U123","U124","U125"};
        int length=array.length;
        System.out.println("11111111111111111111111111");
        button=new Button[length];
        for(int i=0;i

提交回复
热议问题