这样怎么不能动态添加TableRow?
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id = "@+id/mainLayout" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/app_name" /><EditText android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:minLines = "1" android:maxLines = "1" android:gravity = "top|fill_vertical" android:numeric = "decimal" android:id="@+id/sumEdit"/> <TableLayout android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:id="@+id/tableLayout" > </TableLayout></LinearLayout>
public class MainAvitivy extends Activity { private TableLayout tableLayout = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init() ; } public void init(){ tableLayout = (TableLayout) this.findViewById(R.id.tableLayout); tableLayout.setStretchAllColumns(false); TableRow tableRow = new TableRow(tableLayout.getContext()); tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); tableRow.setId(10000); for (int i = 0; i <= 9 ; i++) { Button button = new Button(this); button.setText(" " + i + " "); button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ,ViewGroup.LayoutParams.WRAP_CONTENT)); tableRow.addView(button); Log.i("syso" , i + ""); } tableLayout.addView(tableRow); }}