Java 在tablerow中添加相同的内容会导致fc
我所做的正是本页所说的: 主要代码: xml:Java 在tablerow中添加相同的内容会导致fc,java,android,tablelayout,Java,Android,Tablelayout,我所做的正是本页所说的: 主要代码: xml: 但是当我重复这行的时候 tr.addView(b) 它给了我fc。 知道错误在哪里吗?那是因为添加了相同的按钮。尝试: 可以添加不同的按钮,但不能相同。 this.setContentView(R.layout.main); /* Find Tablelayout defined in main.xml */ TableLayout tl = (TableLayout)findViewById(R.id.myTabl
但是当我重复这行的时候
tr.addView(b)
它给了我fc。
知道错误在哪里吗?那是因为添加了相同的按钮。尝试:
可以添加不同的按钮,但不能相同。 this.setContentView(R.layout.main);
/* Find Tablelayout defined in main.xml */ TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout); /* Create a new row to be added. */ TableRow tr = new TableRow(this); tr.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); /* Create a Button to be the row-content. */ Button b = new Button(this); b.setText("Dynamic Button"); b.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); /* Add Button to row. */ tr.addView(b); /* Add row to TableLayout. */ tl.addView(tr,new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); <code>
..... /* Create a Button to be the row-content. */ Button b = new Button(this); b.setText("Dynamic Button"); b.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); /* Add Button to row. */ tr.addView(b); b = new Button(this); b.setText("Another Dynamic Button"); b.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); /* Add Button to row. */ tr.addView(b); ......