Android 以编程方式向表布局添加行

Android 以编程方式向表布局添加行,android,tablelayout,Android,Tablelayout,嗨,我想在活动第一次启动时用XML数据填充一个表布局,但我是一个新手,所以我真的不知道该怎么做,如果有人知道我该怎么做,你可以动态添加表行 for(int i=0;i<youxmlArray.size();i++){ // get a reference for the TableLayout TableLayout table = (TableLayout)findViewById(R.id.TableLayout01); // create a new Tabl

嗨,我想在活动第一次启动时用XML数据填充一个表布局,但我是一个新手,所以我真的不知道该怎么做,如果有人知道我该怎么做,你可以动态添加表行

for(int i=0;i<youxmlArray.size();i++){
    // get a reference for the TableLayout
    TableLayout table = (TableLayout)findViewById(R.id.TableLayout01);
    // create a new TableRow
    TableRow row = new TableRow(this);
    // create a new TextView for showing xml data
    TextView t = new TextView(this);
    // set the text to "text xx"
    t.setText( "YOUR XML DATA  HERE");
    // add the TextView  to the new TableRow
    row.addView(t);
    // add the TableRow to the TableLayout
    table.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
}
for(int i=0;i


它会遍历所有XML数据直到到达最后一个条目吗?如果有任何问题,请尝试,然后发布代码,我会编辑它
<TableLayout 
android:id = "@+id/TableLayout01" 
android:layout_width = "fill_parent" 
android:layout_height = "wrap_content"   
android:stretchColumns = "0" >
   < TableRow android:id = "@+id/TableRow01" 
   android:layout_width = "wrap_content" 
   android:layout_height = "wrap_content" >
      < TextView android:id = "@+id/TextView01" 
        android:layout_width = "fill_parent" 
        android:layout_height = "wrap_content" 
        android:text = "textfield 1-1" >
        </ TextView >
   </ TableRow >
</ TableLayout >