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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:50:29+00:00 2026-05-18T19:50:29+00:00

I am trying to add a bunch of rows to an empty Table during

  • 0

I am trying to add a bunch of rows to an empty Table during execution. I have tried using some test code but for some reason the screen stays empty. If I had elements in the .XML They do show up, but not the table itself, unless I add some rows/elements inside the .XML file as well.

I would really appreciate some help.

My class extends Activity.

Here is the code to update the Table:

public Runnable UpdateUserList = new Runnable() {
    public void run() {

        TableLayout userTable = (TableLayout) findViewById(R.id.listOfUsers);
        for (String user : userNames) {
            TableRow row = new TableRow(getBaseContext());
            row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

            TextView field = new TextView(getBaseContext());
            field.setText(user);
            field.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

            row.addView(field);
            userTable.addView(row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        }
    }
};

I call the code using a Handler this way, from a Thread:

mHandler.post(UpdateUserList);  

The code does get run and does not print any error.

This is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:background="@drawable/main_bg"
    android:layout_width="fill_parent" android:layout_height="fill_parent">


    <LinearLayout android:orientation="vertical"
        android:layout_marginTop="10px" android:gravity="center_horizontal"
        android:layout_weight="1" android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView android:text="@string/userList"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="25px" />

    </LinearLayout>

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:id="@+id/listOfUsers">
    </TableLayout>

</LinearLayout>

Any help would be very useful. I am very stuck right now.

EDIT: Using ListView

private Runnable UpdateUserList = new Runnable() {
    public void run() {
        ListView userTable = (ListView) findViewById(R.id.listOfUsers);
        userTable.setAdapter(new ArrayAdapter<String>(getBaseContext(),
                R.layout.connectserver, userNames));
    }
};

And the XML:

<ListView android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/listOfUsers" />

Rather than the TableLayout.

  • 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-18T19:50:29+00:00Added an answer on May 18, 2026 at 7:50 pm

    I think you’ll find it easier to use a List instead of TableLayout. One it’s built to hold multiple items and can be easily integrated with a java.util.List or Array. Secondly and more importantly, it is much more memory efficient if you have more than items than are visible.

    With a List it only instantiates views for visible rows + 1 for a list of N. If you use a TableLayout to display the same list it instanties N numbers of views. So as your list grows so does your memory usage with a TableLayout. Not so with a List. It’s the same regardless of how many items you have in that list.

    Furthermore, it provides better way to track what items were selected when the user clicks on an item. TableLayout doesn’t provide any help in this so you have to roll your own mechanism for doing selection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add some UnitTests to a bunch of Cocoa Legacy code. I
I'm trying to add a bunch of TextViews at runtime to a scrollview but
Trying to add a class object into a List using reflection, but when invoking
I am trying to add a bunch of controls dynamically in rows and columns
I am trying to add a bunch of map markers to a map using
I'm trying to add some jQuery stuff to Gmail using a GreaseMonkey script. Adding
I am trying to add some multiple form fields in separate divs. But by
I'm using Gson and am trying to add a bunch of string values into
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got

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.