Am new to android programming, just started learning it the past 6 weeks and am writing a minesweeper game for android, well i've managed to do some part of the game without much issues. However, I've got to design a grid programmatically using TableLayout and TableRow and insert buttons in them; so I've written few lines of code to do that but whenever I run the game i get "Confirm Perspective Switch" error.
Here are the codes I've written -
` 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
}
} `
I think my problem is with the following lines -
`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);
}
}`
It's suppose to create buttons then store them in an array of buttons then insert the buttons in the TableLayout!
And why am I getting the above error?
Could you please help me point out what am doing wrong? As I do not have any errors showing.
Thanks