Search code examples
javaandroidlistviewhorizontalscrollview

What is the best way to put a ListView inside HorizontalScrollView?


I'm trying to make a calendar app and will like to list all the events of a day on a ListView and scroll horizontally the days. When I scroll to the right, ListView should redraw the events for tomorrow. I have all my events in a sqllite database.

This is how my XML looks like:

<?xml version="1.0" encoding="UTF-8"?>       

<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" 
    android:scrollbars="none">

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <ListView android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>

</HorizontalScrollView>

How can I populate the ListView and make it get the new data every time I scroll?


Solution

  • Wrong approach, a ListView can't be nested inside a ScrollView. Use a ViewPager to page the days.