0
내가 정확히 뭐하는 거지 무슨 원인이 페이지는 말한다 : http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout는 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);
나를 제공합니다. 어디에서 오류가 발생했는지 알 수 있습니까?
감사합니다 .it works.but 왜 내가 버튼을 두 번 추가 할 수 없습니까?! –
다른 단추를 추가 할 수 있지만 같지는 않습니다. –