Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:33:45+00:00 2026-05-31T13:33:45+00:00

Am new to android programming, just started learning it the past 6 weeks and

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:33:45+00:00Added an answer on May 31, 2026 at 1:33 pm

    If you want to use a TableLayout then what you need to construct looks like this (using a 4×4 grid as example)

    TableLayout
        TableRow
            Button
            Button
            Button
            Button
        TableRow
            Button
            Button
            Button
            Button
        TableRow
            Button
            Button
            Button
            Button
        TableRow
            Button
            Button
            Button
            Button
    

    1 TableLayout that contains 4 TableRows and each row contains 4 Buttons (a 4×4 grid).
    In code it would like so maybe:

    Button[][] buttonArray = new Button[4][4];
    TableLayout table = new TableLayout(context);
    for (int row = 0; row < 4; row++) {
        TableRow currentRow = new TableRow(context);
        for (int button = 0; button < 4; button++) {
            Button currentButton = new Button(context);
            // you could initialize them here
            currentButton.setOnClickListener(listener);
            // you can store them
            buttonArray[row][button] = currentButton;
            // and you have to add them to the TableRow
            currentRow.addView(currentButton);
        }
        // a new row has been constructed -> add to table
        table.addView(currentRow);
    }
    // and finally takes that new table and add it to your layout.
    layoutVertical.addView(table);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have just started android programming, wrote a quick code, and havn't managed to
Need some advice from you experts out there. I've just started with Android programming
I have just began opengl programming in android and i am fairly new to
I'm new to Android programming and I've coded a simple game where two players
I am relatively new to Android programming. So please, forgive me for writing or
I just started programming for Android when my boss asked me to make him
I'm new to Android programming and trying to wrap my head around this just
i have just started programming for android and i have a little question i
I'm new with Android programming. I'm just wondering whether its possible to set up
I am new to Android programming, and looking for some general knowledge. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.