Adding TableRow add row with a View TextView dynamically to TableLayout Android sample example

Adding TableRow with a View TextView (EditText Button) programmically dynamically to TableLayout Android sample basic example.
MainClass.java

public class MainClass extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
        TableRow row = new TableRow(this);
        TextView tv = new TextView(this);
        tv.setText("This is text");
 
        tl.addView(row);
        row.addView(tv);
 
    }
}

main.xml

<?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"
    >
<TableLayout android:layout_width="fill_parent" 
    android:id="@+id/tableLayout1" android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
This entry was posted in Android Examples Code and tagged , , , , . Bookmark the permalink.


Comments are closed.

13,294 views