首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android初学 相关Button控件

2012-09-03 
android初学 有关Button控件想在主代码(不在XML)里构造Button二维数组(类似于button[][])并显示出来 应该

android初学 有关Button控件
想在主代码(不在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]); 

热点排行