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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:51:06+00:00 2026-05-28T01:51:06+00:00

I am displaying 2 separate tables in a screen. There is no problem displaying

  • 0

I am displaying 2 separate tables in a screen.
There is no problem displaying the first table.
Referring to TableLayout second_table , TableRow tableRow5 , Textfield(s) textView51 , textView52 , textView53

TextFields are basically the columns. Three columns to be displaying
First Name , Last Name , Age.I need to dynamically set the values after fetching that from the server.

I am facing the following exception:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.

I am populating the second table using the following lines of code:

public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.employee_details);
 TableLayout tableLay = (TableLayout) findViewById(R.id.second_table);
 TableRow tableRow = (TableRow) findViewById(R.id.tableRow5);
 TextView fNameTxtView = (TextView) findViewById(R.id.textView51);
 TextView lNameTxtView = (TextView) findViewById(R.id.textView52);
 TextView ageTxtView = (TextView) findViewById(R.id.textView53);
 for(int count = 0; count < tempArrList.size() ; count++){
 fNameTxtView.setText(tempArrList.get(temp.get(0)));
 lNameTxtView.setText(tempArrList.get(temp.get(1)));
 ageTxtView.setText(tempArrList.get(temp.get(2)));
  tableRow.addView(fNameTxtView);
  tableRow.addView(lNameTxtView);
  tableRow.addView(ageTxtView);
  tableLay.addView(tableRow); // Add the new row to our tableLayout
 }
}

I have tried few variations too , but unable to solve the problem.
Any suggestions welcome.

The layout xml follows:
employee_details.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <include android:id="@+id/header" layout="@layout/activity_header" />
    <RelativeLayout android:id="@+id/RelativeLayout1"
        android:background="@drawable/footerbg" android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:layout_alignParentBottom="true"
        android:gravity="center">
        <Button android:layout_alignParentTop="true"
            android:layout_height="50dp" android:layout_width="150dp" android:id="@+id/btn_done"></Button>
    </RelativeLayout>
    <ScrollView android:id="@+id/scrollView01"
        android:layout_above="@id/RelativeLayout1" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_below="@+id/header">
        <LinearLayout android:id="@+id/linear"
            android:orientation="vertical" android:layout_gravity="center_horizontal"
            android:layout_width="match_parent" android:layout_height="match_parent">
            <TextView android:id="@+id/hello_TxtView"
                android:layout_width="wrap_content" android:layout_height="wrap_content">
            </TextView>
            <TableLayout android:id="@+id/first_table"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:background="@drawable/table_shape">
                <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                    <TextView android:id="@+id/textView11"
                        android:layout_width="fill_parent" android:layout_height="match_parent">
                    </TextView>
                    <TextView android:id="@+id/textView12"
                        android:layout_width="fill_parent" android:layout_height="wrap_content">
                    </TextView>
                </TableRow>
            </TableLayout>
            <TableLayout android:id="@+id/second_table"
                android:layout_width="match_parent" android:layout_height="match_parent">
                <TableRow android:id="@+id/tableRow4" android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <TextView android:id="@+id/textView41"
                        android:layout_width="match_parent" android:layout_height="wrap_content">
                    </TextView>
                    <TextView android:id="@+id/textView42"
                        android:layout_width="fill_parent" android:layout_height="wrap_content">
                    </TextView>
                    <TextView android:id="@+id/textView43"
                        android:layout_width="fill_parent" android:layout_height="wrap_content">
                    </TextView>
                </TableRow>
                <TableRow android:id="@+id/tableRow5" android:layout_width="match_parent"
                    android:layout_height="wrap_content" android:background="#f6f7fc">
                    <TextView android:id="@+id/textView51"
                        android:layout_width="match_parent" android:layout_height="wrap_content">
                    </TextView>
                    <TextView android:id="@+id/textView52"
                        android:layout_width="match_parent" android:layout_height="wrap_content">
                    </TextView>
                    <TextView android:id="@+id/textView53"
                        android:layout_width="match_parent" android:layout_height="wrap_content">
                    </TextView>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>
  • 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-28T01:51:07+00:00Added an answer on May 28, 2026 at 1:51 am

    In your for statement you are using the same TextView and TableRow objects and every time you do :

    tableRow.addView(fNameTxtView);
      tableRow.addView(lNameTxtView);
      tableRow.addView(ageTxtView);
      tableLay.addView(tableRow);
    

    you insert in your layout the same TextViews fNameTxtView, lNameTxtView, ageTxtView.
    To avoid this you could create objects dynamically in your for statement like this:

    for(int count = 0; count < tempArrList.size() ; count++){
    TextView fNameTxtView = new TextView(this);
     fNameTxtView.setText(tempArrList.get(temp.get(0)));
    TextView lNameTxtView= new TextView(this);
     lNameTxtView.setText(tempArrList.get(temp.get(1)));
    TextView ageTxtView = new TextView(this);
     ageTxtView.setText(tempArrList.get(temp.get(2)));
    TableRow tableRow = new TableRow(this);
      tableRow.addView(fNameTxtView);
      tableRow.addView(lNameTxtView);
      tableRow.addView(ageTxtView);
      tableLay.addView(tableRow); // Add the new row to our tableLayout
     }
    

    edit: of course you could add IDs for the TextViews if you want do more work on them.

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

Sidebar

Related Questions

I'm having a problem with IE7 displaying a table (don't worry it's used for
I am displaying a scrolled data table in a web page. This table has
I'm trying to select all fields in two separate tables as long as they're
What is the best way to go about displaying an html table with text
First thing, my date format for the field is TIMESTAMP I have a table
I have a UITableView displaying a list of Cities. I want to separate them
I am displaying values from database table using h:datatable, one tupple is displaying in
I am displaying a Timer on a screen. The requirement is I need to
I’m currently displaying a heading name and description text in two separate TextViews from
I am displaying a table in a grid view in a asp.net webpage. I

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.