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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:04:39+00:00 2026-06-07T04:04:39+00:00

I am trying to add rows to a table after a click to a

  • 0

I am trying to add rows to a table after a click to a button (so after the generation of the activity).

My XML code is:

       <TableLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="0,1"
            android:id="@+id/result_table">
            <TableRow 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <TextView
                    style="@style/MyHeader"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Col1" />
                <TextView
                    style="@style/MyHeader"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Col2"  />
            </TableRow>
        </TableLayout>

So when I load the activity I have my table with my only row. Then when I click on my button I do:

    resultTable = (TableLayout)findViewById(R.id.result_table);

    LayoutParams rowLayoutParams = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    LayoutParams cellLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    TableRow tableRow;
    TextView cellValue;
    for(Asdf a : as) {
        tableRow = new TableRow(this);
        tableRow.setLayoutParams(rowLayoutParams);

        cellValue = new TextView(this);
        cellValue.setText(a.getText());
        cellValue.setLayoutParams(cellLayoutParams);
        cellValue.setTextAppearance(this, R.style.MyText);
        tableRow.addView(cellValue);

        cellValue = new TextView(this);
        cellValue.setText("asdf");
        cellValue.setLayoutParams(cellLayoutParams);
        cellValue.setTextAppearance(this, R.style.MyText);
        tableRow.addView(cellValue);

        resultTable.addView(tableRow);
    }

    resultTable.invalidate();

But it doesn’t add anything, and I am sure about that the loop iterates. I don’t get any warning/exception in the logcat.

Can you help me please ??

  • 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-07T04:04:40+00:00Added an answer on June 7, 2026 at 4:04 am

    Try to change the LayoutParams for the added Views like this:

    TableLayout.LayoutParams rowLayoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
    TableRow.LayoutParams cellLayoutParams = TableRow.new LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add new rows in my table, and save them into
Am trying to add in <tr> elements after other <tr> elements in the table
I am trying to add a new row to a table, after it is
I am trying to add a couple of rows to my sqlite database to
I am trying to make a page where users can add as many rows
I am trying to setup jQuery rows, with add/remove row functionality. I got started
I am trying add picture boxes dynamically. My code is as PictureBox picture =
I'm trying to renumber my rows, starting with a given start index, after an
im trying to hide inserted rows into a table that have the class newrow.
I am trying to add rows to my repeater using jQuery using below script.It

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.