想在主代码(不在XML)里构造Button二维数组(类似于button[][])并显示出来 应该如何写代码
------解决方案--------------------
- Java code
Button[][] buttons = new Button[][]{};buttons[1] = new Button[]{new Button(this), new Button(this)};buttons[2] = new Button[]{new Button(this), new Button(this)};
------解决方案--------------------
不好意思,应该是这样:
- Java code
Button[][] buttons = new Button[2][]; buttons[0] = new Button[2]; buttons[1] = new Button[2]; buttons[0][0] = new Button(this); buttons[0][1] = new Button(this); buttons[1][0] = new Button(this); buttons[1][1] = new Button(this); ViewGroup layout = (ViewGroup)this.findViewById(R.id.main); layout.addView(buttons[0][0]); layout.addView(buttons[0][1]); layout.addView(buttons[1][0]); layout.addView(buttons[1][1]);