Is “dragging with longclick” impossible on Android?

偶尔善良 提交于 2020-01-06 05:28:28

问题


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:


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);
                }
            });


来源:https://stackoverflow.com/questions/6440433/is-dragging-with-longclick-impossible-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!