Android-Activity program dynamically generates a table layout manager
The. 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, Li, xiaoli@163.com, beijing },{ 02, Xiaozhang, xiaozhang@163.com, Tianjin };// define the data to be displayed @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); TableLayout layout = new TableLayout (this); // defines the table layout TableLayout. layoutParams layoutParam = new TableLayout. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. FILL_PARENT); // defines the parameters of the layout manager // layout. setBackgroundResource (R. drawable. mldn_logo); // defines the background image for (int x = 0; x <this. titleData. length; x ++) {// cyclically set the table row TableRow row = new TableRow (this); // defines the table row for (int y = 0; y <this. titleData [x]. length; y ++) {TextView text = new TextView (this); text. setText (this. titleData [x] [y]); // sets the text content row. addView (text, y); // Add a number} layout. addView (row); // Add several table rows to the table} super. setContentView (layout, layoutParam); // set display }}