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

  • SEARCH
  • Home
  • 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 8162893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:52:55+00:00 2026-06-06T18:52:55+00:00

Im trying to create a TableLayout dynamically. I want to create rows and columns

  • 0

Im trying to create a TableLayout dynamically. I want to create rows and columns of 3X3.


public class PortAFareActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TableLayout seatTable=new TableLayout(this);        
    ImageButton[][] seatButton=new ImageButton[3][3];
    seatTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    TableRow[] seatRow=new TableRow[3];        
    for (int i = 0; i < 3; i++) {
        seatRow[i]=new TableRow(this);
        seatRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));           
        for (int j = 0; j < 3; j++) {               
            seatButton[i][j]=new ImageButton(this);
            seatButton[i][j].setImageResource(R.drawable.seat);             
            seatButton[i][j].setLayoutParams(new LayoutParams(50,30));
            seatRow[i].addView(seatButton[i][j]);
        }   
        seatTable.addView(seatRow[i]);
    }
    LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
    lin.addView(seatTable,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    lin.invalidate();
    Toast.makeText(this, " "+seatTable.getChildCount() , Toast.LENGTH_SHORT).show();    
 }
}

My Layout XML file contains a LinearLayout with id linLayout

Any help would be appreciated. =)

  • 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-06-06T18:52:57+00:00Added an answer on June 6, 2026 at 6:52 pm

    try this it will work

    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.registration);
    
        TableLayout seatTable=new TableLayout(this);
        ImageButton[][] seatButton=new ImageButton[3][3];
        seatTable.setBackgroundColor(Color.RED);
        seatTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        TableRow[] seatRow=new TableRow[3];
        for (int i = 0; i < 3; i++) {
            seatRow[i]=new TableRow(this);
            seatRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
            for (int j = 0; j < 3; j++) {
                seatButton[i][j]=new ImageButton(this);
                seatButton[i][j].setImageResource(R.drawable.seat);
                //seatButton[i][j].setLayoutParams(new LayoutParams(50,30));//<--------problem 
                seatRow[i].addView(seatButton[i][j]);
            }
            seatTable.addView(seatRow[i]);
        }
        LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
        lin.addView(seatTable);//<-------- not the problem but not required 
        lin.invalidate();
        Toast.makeText(this, " "+seatTable.getChildCount() , Toast.LENGTH_SHORT).show();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a TableLayout dynamically which has all its rows stretched like
I am trying to to create a table of 8x5 images as: @Override public
I am trying to create a basic datasheet in my application using a TableLayout.
I'm trying to create an android screen that has a TableLayout anchored to the
I'm trying to create a buttons dynamically and add them to table layout panel
I've been trying to create a simple layout. It's a 3x3 grid with a
I'm trying to create cells dynamically, they need an image and 3 TextViews. I
I'm trying to create a 1x2 TableLayout with MapView in one of the cells.
I am trying to create a layout that extends to the whole screen if
I'm trying to create a View dynamically (on click). Any person have any idea

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.