I am trying to add rows to a table dynamically at runtime. The code
below shows how I am going about doing that. The page loads without
any errors but there are no rows except the one added in the XML. Can
somebody point out what I am doing wrong here?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_table_layout);
TableLayout table = (TableLayout)findViewById
(R.id.dynamic_table);
TableRow row = null;
TextView label = null;
Button button = null;
for (int i = 0; i < 3; i++){
row = new TableRow(this);
label = new TextView(this);
label.setText("label " + i);
label.setLayoutParams(new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
button = new Button(this);
button.setText("button " + i);
button.setLayoutParams(new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
row.addView(label);
row.addView(button);
table.addView(row);
}
}
The XML for the layout is as follows.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:id="@+id/dynamic_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView android:id="@+id/labels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Labels"/>
<TextView android:id="@+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buttons"/>
</TableRow>
</TableLayout>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---