Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 滑动面板布局中的SwipeListView不';t拦截项目单击事件_Android_Listview_Swipe_Ontouchlistener_Swipe Gesture - Fatal编程技术网

Android 滑动面板布局中的SwipeListView不';t拦截项目单击事件

Android 滑动面板布局中的SwipeListView不';t拦截项目单击事件,android,listview,swipe,ontouchlistener,swipe-gesture,Android,Listview,Swipe,Ontouchlistener,Swipe Gesture,我有一个自定义滑动面板布局中的swipelistview。这是滑块的定义 <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">

我有一个自定义滑动面板布局中的swipelistview。这是滑块的定义

<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>   
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;
    }
 }
布局xml中的swipeListview初始化为:

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"
    />
在代码中,我正在为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
我需要两个行动

a。点击列表项应钻入其他屏幕

b。长时间点击列表项应调用openAnimate

我认为不能使用滑动手势,因为它会与滑块重叠。我如何处理这个问题?我还缺什么吗

谢谢,
Renjith

您可以使用SwipeListView自己的SetWipeListViewListener而不是使用setOnItemClickListener。像这样的东西应该适合你:

enquiryView
        .setSwipeListViewListener(new BaseSwipeListViewListener() {

            @Override
            public void onOpened(int position, boolean toRight) {
            }

            @Override
            public void onClosed(int position, boolean fromRight) {
            }

            @Override
            public void onListChanged() {
            }

            @Override
            public void onMove(int position, float x) {
            }

            @Override
            public void onStartOpen(int position, int action,
                    boolean right) {

            }

            @Override
            public void onStartClose(int position, boolean right) {
            }

            @Override
            public void onClickFrontView(int position) {
                // this is where you want to use click event on listview
            }

            @Override
            public void onClickBackView(int position) {
                // 
            }

            @Override
            public void onDismiss(int[] reverseSortedPositions) {

            }

        });

如果这对你不起作用,请告诉我。

我做到了!但是,长点击会触发onClickFrontView(int)方法