Disable OnClickListener while scaling or dragging

2019-09-17 21:30发布

问题:

Hi I'm using MPAndroidChart and my added OnClickListener is triggered right after i zoomed into or dragged a chart. How can i disable this behavior?

This are my chart properties:

chart.setTouchEnabled(true);        
chart.setScaleEnabled(true);
chart.setDragEnabled(true);        
chart.setPinchZoom(true);
chart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        //this only should run if i really click on the chart, not if i zoom or drag it.
        ...     
    });

Is there an easy way to do it? This ClickListener, ScaleListener and ScaleGestureDetector gang bang ist kinda complicated :/

thanks in advance

回答1:

Implement the ScaleGestureDetector in http://android-developers.blogspot.com.tr/2010/06/making-sense-of-multitouch.html . At onScale Event, remove the OnClickListener with chart.setOnClickListener(null). Then Implement an OnTouchListener and add onClickListener at ACTION_UP.

This should allow you to avoid triggering onClick events at pinch to zoom.