Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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 长时间单击ExpandableListView中的子项_Android_Expandablelistview_Drag_Onlongclicklistener - Fatal编程技术网

Android 长时间单击ExpandableListView中的子项

Android 长时间单击ExpandableListView中的子项,android,expandablelistview,drag,onlongclicklistener,Android,Expandablelistview,Drag,Onlongclicklistener,我使用此源为子项实现ExpandableListView DragNDrop。所有主要函数都在类中,它扩展了ExpandableListView。它覆盖onTouchEvent(MotionEvent)方法,并长时间单击我指示的功能如下: @Override public boolean onTouchEvent(MotionEvent event) { return touchHandler(event); } public boolean touchHandler(final Mo

我使用此源为子项实现ExpandableListView DragNDrop。所有主要函数都在类中,它扩展了ExpandableListView。它覆盖onTouchEvent(MotionEvent)方法,并长时间单击我指示的功能如下:

@Override
public boolean onTouchEvent(MotionEvent event) {
    return touchHandler(event);
}

public boolean touchHandler(final MotionEvent event) {
    final int action = event.getAction();
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    if (prevY < 0) {
        prevY = y;
    }

    int flatPosition = pointToPosition(x, y);
    dragRatio = getHeight() / screenHeight;
    long packagedPosition = getExpandableListPosition(flatPosition);

    Log.i(TAG, "Motion event " + event.getAction());

    Runnable mLongPressed = new Runnable() {
        public void run() {
            Log.i("in thread", "ok");
            event.setLocation(x, y);
            touchHandler(event);
            pressedItem = true;
            isLongPressed = false;
        }
    };

    if (action == MotionEvent.ACTION_DOWN && getPackedPositionType(packagedPosition) == 1) {
        if (dragOnLongPress) {
            Log.i("pressedItem", pressedItem + "");
            if (pressedItem) {
                mDragMode = true;
                pressedItem = false;
                Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(50);
            } else {
                pressedItem = true;
                Log.i("thread: ", "starting");
                handler.postDelayed(mLongPressed, 500);
                return true;
            }
        } else if (x < dragOffset) {
            mDragMode = true;
        }
    }

    if (!mDragMode) {
        /** when user action on other areas */
        if ((pressedItem && Math.abs(prevY - y) > 30)
                || event.getAction() != MotionEvent.ACTION_MOVE) {
            pressedItem = false;
            handler.removeCallbacksAndMessages(null);
        }

        return super.onTouchEvent(event);
    }

 switch(action){
     case:MotionEvent.ACTION_DOWN: bla-bla
     case:MotionEvent.ACTION_MOVE: bla-bla
     case:MotionEvent.ACTION_UP: bla-bla

 }
 I/Motion event MotionEvent.ACTION_DOWN:
 I/pressedItem: false
 I/thread: starting
 I/in thread: ok
 I/Motion event MotionEvent.ACTION_DOWN:
 I/pressedItem: true
 I/Motion event MotionEvent.ACTION_MOVE
 I/Motion event MotionEvent.ACTION_UP
但当未检测到长时间单击时:

I/Motion event MotionEvent.ACTION_DOWN:
I/pressedItem: false
I/Motion event MotionEvent.ACTION_MOVE
I/Motion event MotionEvent.ACTION_MOVE
I/Motion event MotionEvent.ACTION_MOVE
I/Motion event MotionEvent.ACTION_MOVE
...
I/Motion event MotionEvent.ACTION_MOVE
I/Motion event MotionEvent.ACTION_UP
我的德拉格莫德也不转


在这两种情况下,子项压力是相同的,但它可以工作不同。MotionEvent.ACTION\u在显示时移动显示。它可以在定制ROM或htc sense上。在库存ROM中,它几乎总是很好用的。我怎么能修好它?如果您还有其他问题,请告诉我。

长单击必须位于适配器中?它必须位于extends ExpandableListView类中。我无法在适配器中使用某些视图,并为此视图设置OnLongClickListener。它在我的expandableListView类中工作。长时间单击必须在适配器中?它必须在extends expandableListView类中。我无法在适配器中使用某些视图,并为此视图设置OnLongClickListener。它在我的expandableListView类中工作。