首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

这样如何不能动态添加TableRow

2012-05-28 
这样怎么不能动态添加TableRow?main.xmlXML code?xml version1.0 encodingutf-8?LinearLayout xm

这样怎么不能动态添加TableRow?
main.xml

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


Java code
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);    }}


添加不了 ,
运行后,界面顶部只有一个TextView 和 EditText 控件
没有显示我动态添加的按钮

[解决办法]
呵呵,我来

热点排行