Android-Activity程序动态的生成表格布局管理器

来源:互联网 发布:拉依达准则 c语言 编辑:程序博客网 时间:2024/06/13 06:25

.java代码如下:

    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", "姓名", "EMAIL", "地址" },                  { "01", "小李", "xiaoli@163.com",                          "北京" },                  { "02", "小张", "xiaozhang@163.com", "天津" } }; // 定义要显示的数据          @Override          public void onCreate(Bundle savedInstanceState) {              super.onCreate(savedInstanceState);              TableLayout layout = new TableLayout(this); // 定义表格布局              TableLayout.LayoutParams layoutParam = new TableLayout.LayoutParams(                      ViewGroup.LayoutParams.FILL_PARENT,                      ViewGroup.LayoutParams.FILL_PARENT); // 定义布局管理器的参数              //layout.setBackgroundResource(R.drawable.mldn_logo); // 定义背景图片              for (int x = 0; x < this.titleData.length; x++) { // 循环设置表格行                  TableRow row = new TableRow(this); // 定义表格行                  for (int y = 0; y < this.titleData[x].length; y++) {                      TextView text = new TextView(this);                      text.setText(this.titleData[x][y]); // 设置文本内容                      row.addView(text, y); // 加入一个编号                  }                  layout.addView(row); // 向表格之中增加若干个表格行              }              super.setContentView(layout, layoutParam); // 设置显示          }      }  

这里写图片描述

0 0