I have a problem adding my TableLayout to a parent LinearLayout. Only the first view is added to the LinearLayout. I want to create as many TableLayouts as the response.length() is and then add them to the parent LinearLayout.
Here's the Java code:
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.pendingReservations);
for (int i = 0; i < response.length(); ++i) {
final TableLayout tableLayout = (TableLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.confirm_reservation_view,null);
//set the TableLayout content
linearLayout.addView(tableLayout,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
XML codes for the layouts:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollViewConfirmRes"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.konrad.rezerwacje1.ConfirmReservation">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/pendingReservations"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/confirmReservationTableLayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:stretchColumns="1">
<!-- TableLayout content -->
</TableLayout>