您好,我想单击一个按钮,每次单击该按钮时都会向表格行添加一个新按钮。在行中添加了 3 个按钮后,我想动态创建一个新的表格行并向其添加一个新按钮。
如果单击按钮,我知道如何将带有按钮的行添加到 tableLayout。我不知道每次单击时如何修改表格行,以便添加一个额外的按钮。
任何建议都会非常有帮助和赞赏。
以下是我的代码,但这并不完美
public class DynamicTableView extends Activity {
TableLayout mTlayout;
String[] mTextofButton = { "Dipak", "E", "I", "J", "L",
"M", "G", "R", "N", "T", "H", "P",
"K", "Y", "V" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTlayout = (TableLayout) findViewById(R.id.mTlayout);
TableRow tr=new TableRow(this);
for(int i=0;i<mTextofButton.length;i++){
Button btn=new Button(this);
btn.setText(mTextofButton[i]);
tr.addView(btn);
}
mTlayout.addView(tr);
}
}
提前致谢。