Android : SwipeListView in SlidingPaneLayout doesn't intercept item click events

on Thursday, September 25, 2014


I have a swipelistview in a custom SlidingPaneLayout. Here is the slider definition.



<com.tab.mobile.utilities.CustomSlider
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/leftPane"
android:layout_width="320dp"
android:layout_height="match_parent"
android:visibility="gone"/>

<FrameLayout
android:id="@+id/rightPane"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top" />

</com.tab.mobile.utilities.CustomSlider>


Here is the slider class definition.



public class CustomSlider extends SlidingPaneLayout {
private boolean canSlide;
private int orientation;

private static final String TAG_NAME = "SlidingPaneLayout";

public CustomSlider (Context context) {
super(context);
}

public CustomSlider (Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setOrientation(int orientation) {
this.orientation = orientation;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
Log.i(TAG_NAME, "intercepting touch event");

return !canSlide ? super.onInterceptTouchEvent(event) : canSlide;
}


@Override
public boolean onTouchEvent(MotionEvent event) {
if(!canSlide) {
getChildAt(1).dispatchTouchEvent(event);
return true;
}
return super.onTouchEvent(event);
}

@Override
public boolean performClick() {
return super.performClick();
}

public void setCanSlide(boolean canSlide) {
this.canSlide = canSlide;
}
}


And the swipeListview initialization in the layout xml is:



com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/enquiryListView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:listSelector="#00000000"
swipe:swipeBackView="@+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeDrawableChecked="@drawable/choice_selected"
swipe:swipeDrawableUnchecked="@drawable/choice_unselected"
swipe:swipeFrontView="@+id/front"
swipe:swipeOpenOnLongPress="false"
/>


In the code, I am setting the adapter for swipeListview



enquiryView.setSwipeMode(SwipeListView.SWIPE_MODE_BOTH);
enquiryView.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
enquiryView.setSwipeActionRight(SwipeListView.SWIPE_ACTION_REVEAL);
enquiryView.setOffsetLeft(value);
enquiryView.setAnimationTime(50); // Animation time
enquiryView.setSwipeOpenOnLongPress(false);
enquiryView.setAdapter(adapter);

enquiryView.setOnItemClickListener(listener); //this is not working. no events are coming to handler


I need two actions to happen.


a. Tapping a list item should drill into other screen


b. Long tap a list item should call openAnimate


I reckon swipe gestures can not be used as it will overlap with that of the slider. How do I approach this problem? Is there anything I am lacking?


Thanks, Renjith


0 comments:

Post a Comment