0

In my android-app I have a Layout consisting of a FrameLayout containing a GridView. Each grid cell consists of one RelativeLayout with a TextView and a ListView within.

Now I tried to swipe right and left. For this, I implemented an OnSwipeTouchListener based on the SO-Question here and added it to the FrameLayout.

Now, everything works fine. Except if I want to swipe over a ListView. If I swipe on a ListView the app doesn't do anything. I think it's because the ListView captures somehow the TouchEvents itself, without letting my Activity know that there was a TouchEvent at all.

My layout is the following:

<FrameLayout 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"
    tools:context="com.example.Test"
    android:id="@+id/frameLayout">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="16"
        android:rowCount="8"
        android:id="@+id/grid">

        <RelativeLayout
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:id="@+id/ll3"
            android:layout_row="2"
            android:layout_column="1"
            android:orientation="horizontal" >

            <TextView
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Montag"
                android:textSize="40px"
                android:background="#66ff66"
                android:textStyle="bold"
                android:layout_height="55px"
                android:id="@+id/tv1"
                android:layout_width="match_parent" />

            <ListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ffffff"
                android:layout_below="@+id/tv1"
                android:id="@+id/l1">
            </ListView>

        </RelativeLayout>

    </GridLayout>

</FrameLayout>

I set the OnSwipeTouchListener like this:

frameLayout.setOnTouchListener(new OnSwipeTouchListener(this));

I think I'm missing something on the ListView-Side, something like disabling touch on a ListView at all.

Has anyone had this problem too or knows a Solution for this?

Community
  • 1
  • 1
Zeyoza
  • 39
  • 7
  • you can set ontouchlistener on list view and handle them according your need. – Sush May 19 '16 at 09:35
  • I don't need to swipe on the ListView. I need to swipe on the whole layout. Or do you mean, I should - additionally - set the same TouchListener to all of my ListViews too? – Zeyoza May 19 '16 at 09:36
  • yeah.. exactly.. handle touchevents on list view as per your need. – Sush May 19 '16 at 09:38
  • Hmm okay. For me, this could work because I have 'only' 8 ListViews. But what would I do if I had, let's say, 30 ListViews? Don't get me wrong, but this would IMO be against the principles of DRY... – Zeyoza May 19 '16 at 09:41
  • Where DRY principles getting violated. you can use custom listview at all places. – Sush May 19 '16 at 09:49

1 Answers1

0

You can't use swipes combined with ListView scrolling. That's because parent (FrameLayout) method onInterceptTouchEvent returns false, and your FrameLayout don't want to receive any events more, because ListView is scroll container.

You can extend FrameLayout & do something special in onInterceptTouchEvent method for achieve your goals

Petrov Dmitrii
  • 228
  • 1
  • 10