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

The Archive Base Latest Questions

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

Following is my code along with the xml file i have 2 table layouts

  • 0

Following is my code along with the xml file i have 2 table layouts within 2 frame layouts. the 1st table layout is used to set the heading for the table while the 2nd table is used to set the rows dynamically in the 2nd table layout though the heading seems to be fitting perfectly the rows dont align properly below the heading may be i am doing some mistake in setting parameters for the table layout . I am in a fix . Any help will be appreciated. Thank you.

package com.table;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.YuvImage;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import java.util.List;





public class TableActivity extends Activity 
{
    TableLayout table,table_values;
    Button scan,add;
    String value;



    EditText ed1;


    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        createTableLayout(); 
        addrows();


        scan = (Button)findViewById(R.id.read);
        if(scan != null) 
        {
            scan.setOnClickListener(new OnClickListener() {

                public void onClick(View v) 
                {

                }
            });
        }








        try 
        {
            scan.setOnClickListener(new View.OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                   setContentView(R.layout.code);
                    add=(Button)findViewById(R.id.button2);

                }
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        try {
            add.setOnClickListener(new View.OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {


                }
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }








    }




    public void createTableLayout()
     {
            table = (TableLayout) findViewById(R.id.tableLayout1);
          //  table.setBackgroundResource(R.drawable.sky);
            //TableRow tr_heading = new TableRow(this);
            table_values = (TableLayout) findViewById(R.id.tableLayout2);
            TableRow tr_heading = new TableRow(this);
            tr_heading.setId(10);
            tr_heading.setBackgroundColor(Color.GRAY);
            tr_heading.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.FILL_PARENT));



            TextView Serial = new TextView(this);
            Serial.setId(20);
            Serial.setText("Sr No.   ");
            Serial.setTextColor(Color.BLACK);
            tr_heading.addView(Serial); // add the column to the table row








            //TextView label_question = new TextView(this);
            TextView Name = new TextView(this);
            Name.setId(20);
            Name.setText("ID        ");
            Name.setWidth(40);
            Name.setTextColor(Color.BLACK);
            tr_heading.addView(Name); // add the column to the table row

            //TextView label_question = new TextView(this);
            TextView Quantity = new TextView(this);
            Quantity.setId(20);
            Quantity.setText("                             Quantity");
            Quantity.setTextColor(Color.BLACK);
            tr_heading.addView(Quantity); // add the column to the table row


            TextView amt = new TextView(this);
            amt.setId(20);
            amt.setText("            Amt");
            amt.setTextColor(Color.BLACK);
            tr_heading.addView(amt); 


            table.addView(tr_heading, new TableLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT));

     }   


            //--------------------------Adding Rows to your Table --------------------------------------

        public void addrows()
            {

                            Integer count = 0;
                            for (int count1 = 0; count1<3; count1++)
                             { 


                                TableRow tr = new TableRow(this);
                                if (count % 2 != 0)
                                tr.setId(100 + count);
                                tr.setClickable(true);

                                tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));


                                TextView sr = new TextView(this);
                                sr.setText("1");
                                //sr.setGravity(Gravity.CENTER );
                                sr.setPadding(2, 0, 5, 0);
                                sr.setTextColor(Color.WHITE);
                                sr.setClickable(true);
                                tr.addView(sr);








                                TextView idval = new TextView(this);

                                idval.setText(value);
                                idval.setGravity(Gravity.CENTER );
                                idval.setText("             fdfj");
                                idval.setPadding(2, 0, 5, 0);

                                idval.setTextColor(Color.WHITE);
                                idval.setClickable(true);
                                tr.addView(idval);


                                EditText quantity = new EditText(this);
                                //quantity.setId(200 + count);
                                quantity.setGravity(Gravity.CENTER );
                                quantity.setTextColor(Color.BLACK);
                        //      quantity.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                        //      quantity.setWidth(1);
                                quantity.setText("1");
                                quantity.setInputType(InputType.TYPE_CLASS_NUMBER);
                                int val=Integer.parseInt((quantity.getText().toString()));
                        //      quantity.setHeight(2);
                                quantity.setEnabled(true);
                                quantity.setPadding(2,0,5,0);
                                tr.addView(quantity);


                                TextView amount=new TextView(this);
                                amount.setGravity(Gravity.CENTER);
                                amount.setTextColor(Color.WHITE);
                                amount.setClickable(true);
                                //amount.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                                amount.setEnabled(true);
                                //amount.setText("             1000");
                                amount.setText(String.valueOf((    val*10)));
                        //      amount.setWidth(1);
                        //      amount.setHeight(2);
                                tr.addView(amount);


                                // finally add this to the table row
                                table_values.addView(tr, new TableLayout.LayoutParams(
                                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                                count++;



                             }
            }




}



     **Xml file is below:
     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <FrameLayout 
        android:id="@+id/frameLayout1" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent">
    <FrameLayout 
        android:id="@+id/frameLayout2"  
        android:layout_height="match_parent" 
        android:layout_marginTop="40dp" 
        android:layout_marginBottom="70dp" 
        android:layout_width="match_parent">
            <TableLayout 
                android:layout_height="wrap_content" 
                android:id="@+id/tableLayout1" 
                android:layout_width="match_parent">
           </TableLayout>
    <FrameLayout
                android:id="@+id/frameLayout4" 
                android:layout_width="match_parent" 
                android:layout_height="match_parent">
         <TableLayout 
         android:layout_height="wrap_content" android:id="@+id/tableLayout2" android:layout_width="match_parent">
    </TableLayout>

        </FrameLayout>

    </FrameLayout>
    <FrameLayout android:id="@+id/frameLayout3" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_gravity="bottom">

        <Button 
            android:text="Scan" 
            android:id="@+id/button1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" android:layout_marginLeft="10dp">
        </Button>
        <Button 
            android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button"  android:layout_gravity="center_horizontal">
        </Button>

    </FrameLayout>
    </FrameLayout>

</LinearLayout>


screen shot:   https://i.stack.imgur.com/0nqsR.png 


![This is ther screen image[1]


  [1]: https://i.stack.imgur.com/0nqsR.png
  • 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-07T12:39:54+00:00Added an answer on June 7, 2026 at 12:39 pm

    you have 2 framelayouts , so they overlap each other since they are not given anything that makes them to be on beneath the other.

    anyway , i would recommend to use a single tableLayout , or a listView , or a gridLayout .

    here’s an example of a tableLayout:

    http://wowjava.wordpress.com/2011/04/01/dynamic-tablelayout-in-android/

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

Sidebar

Related Questions

I have the following code for grepping an xml file repo, in ant :
I have lots of code like this: FileStream fs = File.Open(@C:\Temp\SNB-RSS.xml, FileMode.Open); using (XmlTextReader
Hi I am working on scraping the XML file. For HTML I have used
i have the following code which will displays result in a UItable view along
I have the following piece of code which outputs a long article: <?php the_content();
I have the following sample xml in a column of xml data type: <diagnostics
I have the following questions concerning code generation for Hibernate annotated DTO/DAO-s: Is it
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I use NSXMLParser for parsing an XML document. I have the following functions (among
I have the following code in my activity: ...... DataCell[i] = new TextView(context,null,R.style.TitleRow); DataCell[i].setText(data[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.