2011-07-29 35 views
0

私は2列のテーブルを動的に追加する必要があるアプリケーションを開発中です。以下は、私が使用していたコードは、これは私のJavaコードAndroidで動的にTableLayoutに行を追加する

  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); 

答えて

0

tb.addView(tr,lp);は、A持っている

<?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> 

.... PLSS助け...私は "ForceClose" エラーを取得しています....ですバグ.. Lpは既にTableRowに設定されているので、tb.addView(tr,lp);

の代わりに tb.addView(tr);を使用してください。