Is “dragging with longclick” impossible on Android

2019-09-12 18:21发布

I am working on charts. I can zoom in-out, dragging... Also I need longclick with dragging. if you need to explain, user can longClıck for see charts values, and user can dragging to left, right with longclick to see other values...Can Android sense it? I use achartengine library.

I can handle it now:) but I have another problem about..

 longPressDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
     @Override
     public void onLongPress(final MotionEvent e) {
        int x = (int) e.getX();
        final int y = (int) e.getY();
        Toast.makeText(context, "long press", Toast.LENGTH_SHORT).show();
        }
       });

But the code doesn't that I understand. What should I do know??

   @Override
  public boolean onTouchEvent(MotionEvent event) {
  if (longPressDetector.onTouchEvent(event)) {
      return true; *** not work.
  }

And can I drag with longClick this way?? Am I right way?

1条回答
戒情不戒烟
2楼-- · 2019-09-12 18:43

OK,I use this..

   longPressDetector = new GestureDetector(getContext(),
            new SimpleOnGestureListener() {
                @Override
                public void onLongPress(final MotionEvent e) {
                    if (!isVolumeChart) {
                        touchHandler.handleLongTouch(true);
                        onLongPress = true;
                    }
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    if (!isVolumeChart && onClickLayout != null)
                        onClickLayout.onClickedView(rootLayout);
                    return super.onSingleTapUp(e);
                }

                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    if (!isVolumeChart) {
                        fitZoom = new FitZoom(mChart);
                        zoomReset();
                        if (volumeView != null) {
                            volumeView.fitZoom = new FitZoom(
                                    volumeView.mChart);
                            volumeView.zoomReset();
                        }
                    }
                    return super.onDoubleTap(e);
                }
            });
查看更多
登录 后发表回答