This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@android:color/holo_blue_dark"
android:text="@string/section_1" />
<ListView
android:id="@+id/lv_section_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@android:color/holo_blue_dark"
android:text="@string/section_2" />
<ListView
android:id="@+id/lv_section_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
</LinearLayout>
The problem is that when first section has many items and it takes up the whole screen, I can not scroll to see second section. With a quick search I just discovered that I can not use ListView within ScollView.
Is there any way to leave this LinearLayout scrollable so I can see all sections that can be added? I need something similar to the iOS UITableView, several sections and headers.
Thank you in advance.
Ok, just to have a list with multiple sections, what I could do to solve my problem was quite simple:
I left just one
ListViewand created a classCustomAdapter. And added items with different types:Set adapter to my
ListView:In my
CustomAdapterI set a different style for each type, section or item. Note that I just want something to differentiate items in aListView.Still accept suggestions for this problem if my solution is too ugly 🙂