Android TableLayout programmatically

RAVITEJA SATYAVADA picture RAVITEJA SATYAVADA · Aug 29, 2011 · Viewed 18.9k times · Source

I learned how to create UI using XML file.But please help me to know how to do it programmatically without using XML files especially for other than LinearLayout.

Answer

Finder picture Finder · Aug 29, 2011

Use the following code to create the TableLayout

TableLayout tbl=new TableLayout(context);

Use the below to create the Table row

TableRow tr=new TableRow(context);

add View into table row

tr.addView(view);

here view may be a TextView or EditText or ect..

add Table Row into TableLayout

tbl.addView(tr);

Like that you can add more table rows into Table Layout.