. Java code is as follows:
Package Org.lxh.demo;import Android.app.activity;import Android.os.bundle;import android.view.viewgroup;import Android.widget.tablelayout;import Android.widget.tablerow;import Android.widget.textview;public Class Mytablelayoutdemo extends Activity {private String titledata[][] = new string[][] {{"ID", "name", "email", "address"},{"01", " Xiao Li "," [email protected] "," Beijing "},{" 02 "," Xiao Zhang "," [email protected] "," Tianjin "}; Define the data to be displayed @overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Tablelayout layout = new Tablelayout (this); Define table layout Tablelayout.layoutparams Layoutparam = new Tablelayout.layoutparams (ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); Define the layout manager's parameter//layout.setbackgroundresource (R.drawable.mldn_logo); Define the background picture for (int x = 0; x < this.titleData.length; + +) {//Loop Set table row TableRow row = new TableRow (this);//define Table row for (in T y = 0; Y < this.titledata[x].length; y++) {TextView text = new TextView (this); Text.settExt (this.titledata[x][y]); Set text content Row.addview (text, y); Add a number}layout.addview (row); Add a number of table rows to the table}super.setcontentview (layout, layoutparam); Settings Display}}
Code DOWNLOAD Link: http://download.csdn.net/detail/yayun0516/8362777
Android-activity program dynamic generation table layout Manager