当我运行我的代码时,它显示9列而不是10.我该如何解决这个问题?
public void maketable() {
int index = 0;
isOn = new Boolean[9][10];
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 10; j++) {
isOn[i][j] = true;
}
}
location = new ImageButton[9][10];
for (int a = 0; a < 9; a++)
{
TableRow row = new TableRow(this);
//TableRow.LayoutParams p = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
//row.setLayoutParams(p);
for (int b = 0; b < 10; b++)
{
location[a][b] = new ImageButton(this);
location[a][b].setBackgroundResource(R.drawable.box1);
location[a][b].setOnClickListener(Onclick);
location[a][b].setId(index++);
row.addView(location[a][b]);
}
tableLayout.addView(row, a);
}
}
答案 0 :(得分:2)
for (int a = 0; a < 9; a++)
仅从0到8。
如果您需要a
从0到9(所以有10行),请使用:
for (int a = 0; a < 10; a++)