0
我這樣做正是這個頁面說:http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout在tablerow的加入同樣的事情會導致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>
XML:
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTableLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:text="Static Button"/> </TableRow> </TableLayout>
但是當我複製該行 tr.addView(b);
它給了我fc。 任何想法錯誤在哪裏?
謝謝you.it works.but爲什麼我不能添加按鈕兩次?! – 2012-04-09 16:09:51
你可以添加不同的按鈕,但不一樣。 – 2012-04-09 18:51:24