Disable OnClickListener while scaling or dragging a View
Asked Answered
B

1

1

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

Brett answered 6/7, 2015 at 23:23 Comment(0)
M
0

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.

Midst answered 7/7, 2015 at 5:5 Comment(1)
Ive written my own myBarChart class and extended it by the BarChart. In my class i wrote a methode setScaleGestureDetector(). I used it to set the Detector. So now when i scale myBarChart the codes doesnt go into onScale() in debug mode... Isnt it the right way to implement them? how do i go into onScale()? :/Brett

© 2022 - 2024 — McMap. All rights reserved.