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 6130447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:34+00:00 2026-05-23T16:51:34+00:00

I have a routine that creates TableRow s dynamically inside a TableLayout that is

  • 0

I have a routine that creates TableRows dynamically inside a TableLayout that is inflated from XML. I am trying to set the TableRows to be a specific width, filling them with a custom button (ButtonElement)… but nothing is showing up. Logging out the TableRow width, and it seems that it is set to 0, which might explain why it is not being displayed.

final Drawable normalBtnBg = getResources().getDrawable(R.drawable.button_states);
TableRow tableRow;
for (int x = 0; x < xDim; x++) {
    tableRow = new TableRow(this);
    tableRow.setLayoutParams(new TableLayout.LayoutParams(400, 20));
    for (int y = 0; y < yDim; y++) {
        // create the new button
        mButtons[x][y] = new ButtonElement(this, x, y);
        mButtons[x][y].setBackgroundDrawable(normalBtnBg);
        mButtons[x][y].setLayoutParams(new LayoutParams(20, 20));

        // add the button to the TableLayout
        tableRow.addView(mButtons[x][y]);
    }

    // add the TableRow to the table
    mButtonGrid.addView(tableRow, new TableLayout.LayoutParams(400, 20));
    Log.d(LOG_TAG, "trWidth - " + tableRow.getWidth());
}

tableRow.getWidth() always returns a value of 0… I have verified the buttons are being generated, as if I add them directly to the mButtonGrid, they are displayed (of course, not in a TableRow, just vertically down).

Any help appreciated.

EDIT:

Figured this out, see my answer below.

  • 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-23T16:51:35+00:00Added an answer on May 23, 2026 at 4:51 pm

    FYI, solved this issue… I was using TableLayout.LayoutParams, but needed to use the TableRow.LayoutParams to make it work (from here):

    final Drawable normalBtnBg = getResources().getDrawable(R.drawable.button_states);
    TableRow tableRow;
    for (int x = 0; x < xDim; x++) {
        tableRow = new TableRow(this);
        tableRow.setLayoutParams(new TableRow.LayoutParams(400, 20));
        for (int y = 0; y < yDim; y++) {
            // create the new button
            mButtons[x][y] = new ButtonElement(this, x, y);
            mButtons[x][y].setBackgroundDrawable(normalBtnBg);
            mButtons[x][y].setLayoutParams(new TableRow.LayoutParams(20, 20));
    
            // add the button to the TableLayout
            tableRow.addView(mButtons[x][y]);
        }
    
        // add the TableRow to the table
        mButtonGrid.addView(tableRow, new TableLayout.LayoutParams(400, 20));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an access form that creates a ppt file (set of slides) from
I have a javascript routine that dynamically creates an HTML page, complete with it's
I have a routine that dynamically changes a select list's selected option when the
I have a routine that creates n instances of a particular workflow and runs
I have a sub routine that creates an array of IP addresses, however I
I'm building a routine that creates a settings.ini file from a database table. I
I have created a site that dynamically creates sub domain addresses for customers when
I have a routine action that creates an comment object, where an answer has_many
have a security routine that, from an array of user names, passwords and permissions
I have this routine that calculates the seconds-to-date for a struct tm . On

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.