Android 表布局行以编程方式添加了子表
我试图以编程方式将一行添加到XML中定义的表中(该行中包含内部表)Android 表布局行以编程方式添加了子表,android,android-layout,Android,Android Layout,我试图以编程方式将一行添加到XML中定义的表中(该行中包含内部表) 现在我只想在表中多次添加此(tabrow)行 我怎么做 像这样的事情应该可以: // get your table layout TableLayout tl = (TableLayout) findViewById(R.id.WhateverYoursIs); // Create new row TableRow tr = new TableRow(this); tr.setLayoutParams(new TableR
现在我只想在表中多次添加此(tabrow)行
我怎么做 像这样的事情应该可以:
// get your table layout
TableLayout tl = (TableLayout) findViewById(R.id.WhateverYoursIs);
// Create new row
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
// Create textview
TextView t = new TextView(this);
//
// configure your textview's and do this 2 more times
//
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
// add textview to row
tr.addView(t);
//
// do this 2 more times
//
// add row to table
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
您只需根据需要的频率将行创建内容放入一个循环中您可能希望看到我很久以前的问题:@kevin I厌倦了按您的方式查看menuLayout=inflater1.inflate(R.id.timealarm,mainLayout,true);这条线有错误
// get your table layout
TableLayout tl = (TableLayout) findViewById(R.id.WhateverYoursIs);
// Create new row
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
// Create textview
TextView t = new TextView(this);
//
// configure your textview's and do this 2 more times
//
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
// add textview to row
tr.addView(t);
//
// do this 2 more times
//
// add row to table
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));