Setting Button ID programmatically

前端 未结 6 1352
慢半拍i
慢半拍i 2021-01-01 04:10

Android 2.3.3

I have a table with N rows and N columns. For each row, I should add 4 buttons dynamically, and later do actions based on the button clicked. I know we

6条回答
  •  离开以前
    2021-01-01 04:50

    for (int i=0;i

    And add this listner outside the any method and inside class

    OnClickListener btnclick = new OnClickListener() {
    
        @Override
        public void onClick(View view) {
    
            switch(view.getId()) {
                case 1:
                    //first button click
                    break;
                    //Second button click
                case 2:
                    break;
                case 3:
                    //third button click
                    break;
                case 4:
                    //fourth button click
                    break;
                 .
                 .
                 .
                default:
                    break;
            }
        }
    };
    

提交回复
热议问题