【发布时间】:2012-03-20 05:02:54
【问题描述】:
我是 android 编程的新手,过去 6 周才开始学习它,并且正在为 android 编写一个扫雷游戏,我已经成功地完成了游戏的某些部分而没有太多问题。但是,我必须使用 TableLayout 和 TableRow 以编程方式设计一个网格并在其中插入按钮;所以我写了几行代码来做到这一点,但每当我运行游戏时,我都会收到“确认透视切换”错误。
这是我写的代码 -
` public class Game extends Activity implements OnClickListener {
Button[][] btn = new Button[6][6];
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gamegrid);
int i, j;
LinearLayout layoutVertical = (LinearLayout) findViewById(R.layout.gamegrid);
//create a new TableLayout
TableLayout table = null;
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
LayoutParams param = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
for(i = 0; i <6; i++){
table = new TableLayout(this);
table.setWeightSum(5);
layoutVertical.addView(table, param);
for(j=0; j<7; j++){
btn[i][j] = new Button(this);
table.addView(btn[i][j], param);
btn[i][j].setOnClickListener(this);
}
} return;
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
} `
我认为我的问题在于以下几行 -
`for(i = 0; i <6; i++){
table = new TableLayout(this);
table.setWeightSum(5);
layoutVertical.addView(table, param);
for(j=0; j<7; j++){
btn[i][j] = new Button(this);
table.addView(btn[i][j], param);
btn[i][j].setOnClickListener(this);
}
}`
假设创建按钮,然后将它们存储在按钮数组中,然后将按钮插入 TableLayout!
为什么会出现上述错误?
你能帮我指出做错了什么吗?因为我没有显示任何错误。
谢谢
【问题讨论】: