2011-07-29 73 views
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); 

回答

0

tb.addView(tr,lp);有错误.. Lp是布局参数已设置为TableRow所以只需使用tb.addView(tr);而不是tb.addView(tr,lp);

相关问题