3

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 ListViews

is there a workaround for this ?

thanks

**

EDIT:

** here's my activity layout

<GridView
        android:id="@+id/grid"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:verticalSpacing="35dp"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:columnWidth="300dp"
        android:stretchMode="columnWidth"

        />
</LinearLayout>

each gridview item has the following layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

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

</LinearLayout>
Mina Wissa
  • 10,923
  • 13
  • 90
  • 158

2 Answers2

2

set attribute android:scrollingCache="true" in your ListView

<ListView android:id="@+id/android:list" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:scrollingCache="true"
   android:layout_weight="1" />
PC.
  • 6,870
  • 5
  • 36
  • 71
1

You cannot have a scrollable child view within a parent view that is scrollable. Google does not recommend it... and it's really messy. Read this

There have been people who've been trying to do a workaround (which doesn't look pretty), but I doubt it will work for you. But you can read it anyways and see if you can make it work for you. Enjoy.

One of the main reasons why it wont work is because of the way scrollable views handle touch. There's a method called dispatchTouchEvent() and onInterceptTouchEvent() that decides whether to intercept the touch event or pass it to it's children. For scrollable views, they will always intercept "swipe" movements. So it will never go to your children.

You can try to modify it, but if you think about it, how will you know if you're trying to scroll the parent or if you're trying to scroll the child? Imagine if the one of your scrollable children ends up taking the width of your screen, but then you want to scroll your parent, how will you manage that?

Summary: it's not recommended .... if you really insist... then go ahead and write your own custom view to handle the logic. But i guarantee you it wont be pretty and will almost never work for all use cases.

Community
  • 1
  • 1
wnafee
  • 2,126
  • 16
  • 23