Question

Myy linearLayout contains four textviews and four listviews. The problem is that only two listviews are visible on the screen, if i want to scroll down the second listview starts scrolling not the whole layout. I've tried putting them in a scrollView but they got all collapsed.

XML code:

<LinearLayout
                android:id="@+id/mainpageContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/TextView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

                <ListView
                    android:id="@+id/listView2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>

                <TextView
                    android:id="@+id/TextView2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

                <ListView
                    android:id="@+id/listView3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                </ListView>

                <TextView
                    android:id="@+id/TextView3"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

                <ListView
                    android:id="@+id/listView4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>

                <TextView
                    android:id="@+id/TextView4"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

                <ListView
                    android:id="@+id/listView5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>
            </LinearLayout>

Every listview will contain exactly 4 items only. Any help guys?

Was it helpful?

Solution

You should use only one ListView and MergeAdapter instead of four ListViews. MergeAdapter accepts a mix of Adapters and Views and presents them as one contiguous whole to whatever ListView it is poured into. This is good for cases where you have multiple data sources, or if you have a handful of ordinary Views to mix in with lists of data, or the like.

MergeAdapter library: https://github.com/commonsguy/cwac-merge

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top