0

I was getting started with android app development and my requirement is to add a list with some headers in it. I managed to implement this using a combinations of textView and listView. Following is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView

xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:animateLayoutChanges="true"
android:fillViewport="true"
android:orientation="vertical">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.home.HomeFragment">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="vertical"
        android:padding="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Header 1" />

        <ListView
            android:id="@+id/list1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/sports_array" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Header 2" />

        <ListView
            android:id="@+id/list2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/sports_array" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Header 3" />

        <ListView
            android:id="@+id/list3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/sports_array" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Header 4" />

        <ListView
            android:id="@+id/list4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/sports_array" />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

And sports_array is equal to:

 <string-array name="sports_array">
        <item>Shuttle Badminton</item>
        <item>Tennis</item>
        <item>FootBall</item>
        <item>Basket Ball</item>
        <item>Table Tennis</item>
        <item>Chess</item>
        <item>Hockey</item>
    </string-array>

Now the problem is that it loads all the lists on the UI but it doesn't scroll down to make the elements visible that are not displayed.

Bilal
  • 558
  • 8
  • 18

1 Answers1

0

Solved this by using custom listView that are not scrollable.

Ref: Non-scrollable ListView inside ScrollView

Bilal
  • 558
  • 8
  • 18