1

I have an ExpandableListView and I am using a SwipeDetector to know when a row of this list is swiped.

The implementation of this dectetor comes from this post.

Everything works fine.

Then, I have added a Button on each row and I want to be able to know:

  • When the button is cliked
  • When the row is swiped

This is the layout used for each (except for headers) row of the list:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#fff"
    android:layout_height="wrap_content" >

    <Button
        android:text="Button"
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>

Now, the problem is that the swipe gesture is no more detected because the Button catches the event. Since they are lots of threads about this subject I tried several things but nothing works (at least I did not manage to make it work). Here is the different things I tried:

  • Set the android:focusable property to false on the Button
  • Set the android:descendantFocusability property to blocksDescendants on the RelativeLayout
  • Follow this post and override the onInterceptTouchEvent

Last points:

  • I can't set the SwipeDetector directly on the Button instead of the ListView's item because in some cases there will be no button (or many).
  • I can't use android:clickable="false" on the Button because I need to implement the onClick method.
Community
  • 1
  • 1
G.T.
  • 1,557
  • 1
  • 12
  • 24

0 Answers0