【发布时间】:2011-05-05 15:10:57
【问题描述】:
您好,下面是我的前端和后端代码。我想要做的是动态添加一个文本视图和一行到 xml 的表格布局部分。有人看错了吗?
<?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);
【问题讨论】:
-
你没有真正描述什么是问题,你为什么认为有问题..
标签: android textview tablelayout