Array of Buttons in Android

后端 未结 6 1896
庸人自扰
庸人自扰 2020-12-29 12:34

I want to map the buttons to an array of buttons and the code has no errors while compiling but there is force close when i run it:

Button buttons[];

@Overr         


        
6条回答
  •  天命终不由人
    2020-12-29 12:49

    I had situation like this, I chose different approach. I stored id into integer array.

    Int[] btnarr = new int[3];
    
    btn[0]=R.id.button1; // give your ID 
    
    Button btn = (Button).findViewById(cc[i]);
    

提交回复
热议问题