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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:46:31+00:00 2026-05-27T03:46:31+00:00

I am trying to add rows to a TableLayout that I define in an

  • 0

I am trying to add rows to a TableLayout that I define in an XML file. The XML file contains a header row for the table.

I can add new rows quite well using info from various tutorials but the code required for setting up the layout for the new rows is a horrendous mess and it seems like a pain in the ass to maintain whenever the layout for the header row changes.

Is it possible to create new rows to a TableLayout while still defining the row layout in XML? For example define a template row in XML, obtain a handle to it in code and then clone the template whenever I need it.

Or is the right way to do this somehow completely different?

  • 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-27T03:46:31+00:00Added an answer on May 27, 2026 at 3:46 am

    Your proposed approach will work fine and it more or less matches the common pattern used when populating ListView items.

    Define a layout that contains a single row. Obtain a LayoutInflater by using LayoutInflater.from(myActivity). Use this inflater to create new rows using your layout like a template. Generally you will want to use the 3-argument form of LayoutInflater#inflate passing false for the third attachToRoot parameter.

    Let’s say you wanted to use a template layout with a label and a button in each item. It might look something like this: (Though yours would define your table rows instead.)

    res/layout/item.xml:

    <LinearLayout android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <TextView android:id="@+id/my_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        <Button android:id="@+id/my_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>
    

    Then at the point where you inflate:

    // Inflate the layout and find the component views to configure
    final View item = inflater.inflate(R.layout.item, parentView, false);
    final TextView label = (TextView) item.findViewById(R.id.my_label);
    final Button button = (Button) item.findViewById(R.id.my_button);
    
    // Configure component views
    label.setText(labelText);
    button.setText(buttonText);
    button.setOnClickListener(buttonClickListener);
    
    // Add to parent
    parentView.addView(item);
    
    • 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
I am trying to add a new row to the table. The new row
I'm trying to add table rows programmatically following the code here /* Find Tablelayout
I am trying to add a new row to a table, after it is
I am trying to setup jQuery rows, with add/remove row functionality. I got started
I am trying to add a new row into a gridview but for some
I'm trying to add rows dynamically to a System.Web.UI.WebControls.Table control in ASP.NET. I found
I'm trying to add an onclick event to a table row through Javascript. function
I'm trying to add a new row to a DataGridView from FORM 2 but
I am trying to use JavaScript to add rows to a table dynamically using

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.