Я пытаюсь добавить строки таблицы динамически ...... Ниже мой Java-код:Динамически добавить строки в TableLayout
TableLayout tl = (TableLayout) findViewById(R.id.tablerow);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
Мой код XML является
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tablerow"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:id="@+id/content"
android:singleLine="false" />
</TableRow>
</TableLayout>
Но я получаю ошибку на этой линии:
final TableLayout tl = (TableLayout)findViewById(R.id.tablerow);
Ошибка я получаю не может бросить из поля зрения в TableLayout
Любая помощь будет оценена
Почему вы используете динамическое раздувание? setContentView() уже должен был сделать все необходимое раздувание. – 2010-11-25 11:05:57