动态添加textview到表格布局
问题描述:
嗨下面是我的前端和后端代码。我想要做的是动态地添加一个textview和一行到xml的表格布局部分。有没有人看到任何错误?动态添加textview到表格布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relLayout" android:layout_height="wrap_content"
android:layout_width="fill_parent">
<EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:text="Enter Stock to Add" android:textSize="15px"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_marginLeft="20px" android:layout_marginRight="20px" android:layout_marginTop="20px"></EditText>
<Button android:id="@+id/addButton" android:layout_width="100px"
android:layout_below="@id/editText1" android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:text="Add Stock" android:layout_marginRight="20px" android:textSize="15px"></Button>
</RelativeLayout>
<TableLayout android:id="@+id/tableLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent">
</TableLayout>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
tv.setText("This is text");
tl.addView(row);
row.addView(tv);
//set the layout of the view
setContentView(R.layout.main);
你没有真正描述什么是_问题_,你为什么认为有什么问题.. – Adinia 2011-03-18 16:16:26