Я отчаянно пытаюсь добавить ImageView в TableRow, но почему-то не могу. Я могу добавить новый TableRow в TableLayout, но для строки я ничего не могу добавить. Я уже пробовал сделать недействительным строку, или представление, которое я вставляю, но никакой разницы.Невозможно добавить представление в TableRow динамически
Код:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.page2,
container, false);
Button soundBtn = (Button) rootView.findViewById(R.id.p2b1);
soundBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
LayoutInflater inflater = activity.getLayoutInflater();
TableRow row = (TableRow)inflater.inflate(R.layout.page2, null).findViewById(R.id.p2row9);
View child = (View)inflater.inflate(R.layout.dummyview, null);
row.addView(child, 0);
}
});
}
и XML является:
<TableLayout
android:id="@+id/p2table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
android:id="@+id/p2row9"
android:layout_width="wrap_content"
android:layout_height="200dip"
android:paddingTop="10dip">
</TableRow>
</TableLayout>
и мой dummyview является:
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="0.3"
android:layout_height="1dp"
android:gravity="center"
android:background="@color/textbody" />
Любая помощь приветствуется.