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:focusableproperty tofalseon theButton - Set the
android:descendantFocusabilityproperty toblocksDescendantson theRelativeLayout - Follow this post and override the
onInterceptTouchEvent
Last points:
- I can't set the
SwipeDetectordirectly on theButtoninstead of theListView's item because in some cases there will be no button (or many). - I can't use
android:clickable="false"on theButtonbecause I need to implement theonClickmethod.