0
我正在研究需要將行添加到具有2列動態列的應用程序。下面是我使用....我得到一個 「ForceClose」 錯誤... PLSS幫助代碼....在Android中動態添加行到TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:id="@+id/b1" />
</TableRow>
</TableLayout>
這是我的java代碼
TableLayout tb=(TableLayout)findViewById(R.id.table);
TableRow tr=new TableRow(getBaseContext());
Button b1=(Button)findViewById(R.id.b1);
LayoutParams lp=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(lp);
b1.setLayoutParams(lp);
b1.setText("I NEED HELP ! SOS ");
tr.addView(b1);
tb.addView(tr,lp);