I am trying to add a single textview row to a table in android the row should merge and center the width of the table
I am able to achieve this using XML
<TableLayout>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/red_cell_shape"
android:text="code"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/red_cell_shape"
android:padding="5dp"
android:text="desc"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/red_cell_shape"
android:text="status"
android:textAlignment="center"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/tremptyrow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/red_cell_shape">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/no_fg_scanned"
android:padding="5dp"
android:layout_span="6"
android:textAlignment="center"
android:textColor="@color/red" />
</TableRow>
</TableLayout>
this is what it should look like

but I want to do it dynamically in java and tried this but did not work
