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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:04:26+00:00 2026-06-14T23:04:26+00:00

I’m develop a dynamic table layout using java code the first row is in

  • 0

I’m develop a dynamic table layout using java code

the first row is in xml

<TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:stretchColumns="*"
            android:id="@+id/TableMain" >

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="2dip"
                android:background="#000000" >

                <LinearLayout
        android:id="@+id/lTable11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_margin="1dip"
                    android:layout_weight="2"
                    android:background="#C0C0C0"
                    android:text="Grade" 
                    android:gravity="right"
                    android:padding="5dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_margin="1dip"
                    android:layout_weight="2"
                    android:background="#C0C0C0"
                    android:text="Hourse"
                    android:gravity="right" 
                    android:padding="5dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_margin="1dip"
                    android:layout_weight="6"
                    android:background="#C0C0C0"
                    android:text="Subject Name"
                    android:gravity="right"
                    android:padding="5dp" 
                      />

                    </LinearLayout>

            </TableRow>
        </TableLayout>

the remain rows is in the java part which is have the same property in xml

TextView tvRowGrades[]=new TextView[gotSubName.length];
    TextView tvRowHourse[]=new TextView[gotSubName.length];
    TextView tvRowSubName[]=new TextView[gotSubName.length];

    TableRow row[]=new TableRow[gotGradeItem.length];
    LinearLayout LRow[]=new LinearLayout[gotGradeItem.length];
    tableMain=(TableLayout)findViewById(R.id.TableMain);

    for(int i=0;i<gotHourse.length;i++){
        row[i]=new TableRow(this);
        TableRow.LayoutParams lRow=new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
        lRow.setMargins(2, 2, 2, 2);
        row[i].setLayoutParams(lRow);
        row[i].setBackgroundColor(Color.BLACK);

        LinearLayout.LayoutParams lpLRow=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        LRow[i]=new LinearLayout(this);
        LRow[i].setLayoutParams(lpLRow);
        LRow[i].setGravity(Gravity.CENTER);
        LRow[i].setOrientation(LinearLayout.HORIZONTAL);

        tvRowGrades[i]=new TextView(this);
        tvRowGrades[i].setText(gotGradeItem[i]);
        android.widget.LinearLayout.LayoutParams lpTvOther=new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.FILL_PARENT, 2);
        lpTvOther.setMargins(1, 1, 1, 1);
        tvRowGrades[i].setPadding(5, 5, 5, 5);
        tvRowGrades[i].setGravity(Gravity.RIGHT);
        tvRowGrades[i].setLayoutParams(lpTvOther);
        LRow[i].addView(tvRowGrades[i]);

        tvRowHourse[i]=new TextView(this);
        tvRowHourse[i].setText(gotHourse[i]+"");
        tvRowHourse[i].setPadding(5, 5, 5, 5);
        tvRowHourse[i].setGravity(Gravity.RIGHT);
        tvRowHourse[i].setLayoutParams(lpTvOther);
        LRow[i].addView(tvRowHourse[i]);

        tvRowSubName[i]=new TextView(this);
        tvRowSubName[i].setText(gotSubName[i]);
        android.widget.LinearLayout.LayoutParams lpTvSubName=new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.FILL_PARENT, 6);
        lpTvSubName.setMargins(1, 1, 1, 1);
        tvRowSubName[i].setPadding(5, 5, 5, 5);
        tvRowSubName[i].setGravity(Gravity.RIGHT);
        tvRowSubName[i].setLayoutParams(lpTvSubName);
        LRow[i].addView(tvRowSubName[i]);

        row[i].addView(LRow[i]);
        tableMain.addView(row[i]);
    }

When i run the application the table is not displaying
please i want solve this problem

  • 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-14T23:04:27+00:00Added an answer on June 14, 2026 at 11:04 pm

    change the TableRow width to match_parent

               <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="2dip"
                android:background="#000000" >
    

    The problem is that your row’s width is defined by it’s content (wrap_content), and your content’s width (the LinearLayout that is inside the row) is defined by the parent.

    You can also delete the LinearLayout and put the TextView items directly in the TableRow as it extends LinearLayout.

    For the other rows that you add in the code you should also change the LayoutParams:

     TableRow.LayoutParams lRow=new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.