Iam working on an android app and using AChartEngine for bar charting. Everything is working as it should except that I can't figure out which bar in the graph is touched (not clicked). It seems that .getCurrentSeriesAndPoint() isn't working within the OnTouchListener. It's everytime returning NULL. When I'm using OnClickListener everything is working fine, but I need to know which bar is touched (Action_Down and Action_Up) not clicked.
Is .getCurrentSeriesAndPoint() not working in a TouchListener in general? Is there a workaround or another way to realize which bar is touched?
mChartView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:{
Toast.makeText(MainActivity.this, "DOWN", Toast.LENGTH_SHORT) .show();
if(seriesSelection != null) touchedBar = seriesSelection.getPointIndex();
break;}
case MotionEvent.ACTION_UP:{
Toast.makeText(MainActivity.this, "UP", Toast.LENGTH_LONG) .show();
touchedBar = 0;
break;}
default: break;
}
mRenderer.removeAllRenderers();
r.setColor(Color.RED);
r.setSelectedBar(ClickedBar);
mRenderer.addSeriesRenderer(r);
mChartView.repaint();
return true;
}
});
kind regards Christian
It should work with the touch listener. However, you still have to do this:
mRenderer.setClickEnabled(true);
AChartEngine uses the onTouchEvent internally, so it is possible that your touch event is called after the ACE one, so this may be the cause for not getting the expected values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With