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

The Archive Base Latest Questions

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

I’m using eclipse + android SDK. I’m trying to create a table with data

  • 0

I’m using eclipse + android SDK.

I’m trying to create a table with data provided by sensors. I get the information correctly, by i’m having problems to make a table to show it in XML dinamically.

This is the sensorinfo.XML:

<?xml version="1.0" encoding="utf-8"?>

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


<TableRow>

    <TextView
            android:layout_column="1"
            android:text="@string/sensor_name_title"
            android:padding="3dip" />

    <TextView
            android:layout_column="2"
            android:text="@string/sensor_type_title"
            android:padding="3dip" />
    <TextView
            android:layout_column="3"
            android:text="@string/sensor_value_title"
            android:padding="3dip" />
    <TextView
            android:layout_column="4"
            android:text="@string/sensor_unit_title"
            android:padding="3dip" />
</TableRow>

   <View
    android:layout_height="4dip"
    android:background="#FF909090" />

</TableLayout>

And this is the code of my activity:

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState); 

    getSensorInfo();
    setContentView(R.layout.sensorinfo);

    setInfoByView();

}

And

    private void setInfoByView()
{
    /* Find Tablelayout defined in xml */
    TableLayout myTableLayout = (TableLayout)findViewById(R.id.SensorInfoTableLayout);
    /* Create a new row to be added. */
    TableRow myTableRow = new TableRow(this);
    myTableRow.setLayoutParams(new LayoutParams(
                        LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT));
    /* Create a Button to be the row-content. */
    Button b = new Button(this);
    b.setText("Dynamic Button");
    b.setLayoutParams(new LayoutParams(
                        LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT));
    myTableRow.setBackgroundColor(5);
    /* Add Button to row. */
    myTableRow.addView(b);
    /* Add row to TableLayout. */
    myTableLayout.addView(myTableRow,new TableLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT,
              LayoutParams.WRAP_CONTENT));
}

THIS IS A TEST, i’m trying to include a button dinamically, if work, i will put the information i get from getSensorInfo();

But my Activity looks like this:

ACTIVITY IMAGE

What could I be doing wrong?

All the info i found was THIS, but the answers didn’t help me.

  • 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-28T04:18:06+00:00Added an answer on May 28, 2026 at 4:18 am

    First of all create one Table Layout in your XML file like this :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#BFD6E8">
    
    <ScrollView android:id="@+id/image_scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    
        <TableLayout android:id="@+id/image_table"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        </TableLayout>
    
    </ScrollView>
    
    </LinearLayout>
    

    Then use this code for creating dynamic row inside the Table Layout :

             TableLayout image_table=null;
             image_table=(TableLayout)findViewById(R.id.image_table);
    
            for(int i=0; i<10; i++){
                TableRow tableRow=new TableRow(this);
                tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                tableRow.setGravity(Gravity.CENTER_HORIZONTAL);
                tableRow.setPadding(5, 5, 5, 5);
                for(int j=0; j<1; j++){
                    Button bttn=new Button(this);
                    bttn.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                    bttn.setText(Hello);
                    tableRow.addView(image, 200, 200);
                }
                image_table.addView(tableRow);
            }
    

    FINAL (test) SOLUTION:

    private void setInfoByView2()
    {
        TableLayout myTableLayout = null;
        TableRow myTableRow = new TableRow(this);
        myTableLayout = (TableLayout)findViewById(R.id.SensorInfoTableLayout);
    
        myTableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        //myTableRow.setGravity(Gravity.CENTER_HORIZONTAL);
        myTableRow.setPadding(5, 5, 5, 5);
        Button bttn = new Button(this);
        bttn.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        bttn.setText("Hello");
        myTableRow.addView(bttn, 200, 200);
        myTableLayout.addView(myTableRow);
    }
    

    And the button is visible now.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.