I've been trying to search around for a while now on SO and Google however can't quite get this right. I have a ListView with a customadapter associated with it. Within the layout for this ListView, I have another ListView (also with its own customadapter), which only has between 0 and 4 items in it.
The height of the row in the outer/first listview needs to expand and contract based on how many rows are in the inner/nested listview, however this is not happening. It will only ever, when left to its own devices, show one row.
I've been pretty much randomly assigning various LinearLayouts and ListViews with layout_height:0
and layout_weight:1
, while varying values of match_parent
vs wrap_content
, but to no avail.
It's a simple fix, I know, but can't work out which element in the layout needs which parameters. I don't want to do this programatically either. It should only need the right combination of layout attributes.
Thanks in advance.
Layout file for the OUTER ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffdddd">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ddffdd"
>
<ListView
android:id="@+id/lvInnerListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eeeeee">
<TextView
android:id="@+id/tvSomeOtherText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Layout file for the INNER/NESTED Listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#ddddff">
<TextView
android:id="@+id/tvText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Layout file for the fragment itself
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Values"
android:id="@+id/btnGetValues"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:textColor="#ffffff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Response from server"
android:id="@+id/tvResponse"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lvOuterListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>