JP Chauhan JP Chauhan - 6 months ago 39
Android Question

Scrollable Custom Listview inside Gridview in android

I have a GridView that displays items, each item is a ListView.
The problem is that I can't scroll the ListView items, seems like the GridView is obtaining the focus or preventing it from the ListView

* activity_layout.xml *

<GridView
android:id="@+id/listMonthly"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:divider="@drawable/above_shadow"
android:numColumns="7"
android:clipToPadding="true"
android:fitsSystemWindows="true"
android:dividerHeight="10dp"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:listSelector="@android:color/transparent"
android:padding="10dp" android:stretchMode="columnWidth">

</GridView>


* custom_calendar.xml *

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="@drawable/border"
android:orientation="horizontal">

<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dividerHeight="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:overScrollMode="always"
android:id="@+id/customList"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:layout_weight="1"
android:id="@+id/txtdt"/>

</LinearLayout>


The View is ... calendar View

as figure shows .. i have a listview on every gridview item.
how to make this listview scrollable.

Answer

It was discouraged to use scrollable inside another scrollable view in Android. But in the latest support library you can find NestedScrollView which was added for such cases. You can use it instead of you ListView or GridView. More info you can find in this tutorial.