Search code examples
androidachartenginetouch-eventonlongclicklistener

Is "dragging with longclick" impossible on Android?


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?


Solution

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