PowenKo, android, Tutorial 020-6, Layout, TableLayout, dynamically adding rows to TableLayout

September 3, 2011   ·   0 Comments

package com.powenko.Tutorial_UI_Layout_TableLayout_DynamicallyAddingRowsToTableLayout;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;

public class Tutorial_UI_Layout_TableLayout_DynamicallyAddingRowsToTableLayoutActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    	 /* Find Tablelayout defined in main.xml */
        TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);
             /* Create a new row to be added. */
             TableRow tr = new TableRow(this);
             tr.setLayoutParams(new LayoutParams(
                            LayoutParams.FILL_PARENT,
                            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.FILL_PARENT,
                            LayoutParams.WRAP_CONTENT));
                  /* Add Button to row. */
                  tr.addView(b);

        /* Add row to TableLayout. */
        tl.addView(tr,new TableLayout.LayoutParams(
                  LayoutParams.FILL_PARENT,
                  LayoutParams.WRAP_CONTENT));
     }

}

res\layout\main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myTableLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
     <TableRow
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">

          <Button android:text="Static Button"/>
     </TableRow>
</TableLayout>

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon