David Rawson's answer is just perfect and answers the question leaving no stones unturned. However, for my situation, I found the answer by firegloves more useful. I actually get the Entry
object using firegloves' solution to obtain values from. Following is the code for what solved my problem but please do note that this solution is hacky and is not advised until absolutely necessary. If you want a clean solution, David Rawson's answer already covers that.
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
final long selectionTime = System.currentTimeMillis();
final Highlight copyHighlight = h;
final Entry copyEntry = e;
final boolean[] isTapped = {false};
mChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (!isTapped[0]) {
final long doubleTapTime = System.currentTimeMillis();
if (doubleTapTime - selectionTime < 300) {
if ((motionEvent.getX() <= copyHighlight.getDrawX() + 50
&& motionEvent.getX() >= copyHighlight.getDrawX() - 50)
&& (motionEvent.getY() <= copyHighlight.getDrawY() + 50
&& motionEvent.getY() >= motionEvent.getY() - 50)) {
if (copyEntry.getX() == 1.0f && copyEntry.getY() == 1.0f) {
Toast.makeText(MainActivity.this, "1,1", Toast.LENGTH_SHORT).show();
} else if (copyEntry.getX() == 2.0f && copyEntry.getY() == 2.0f) {
Toast.makeText(MainActivity.this, "2,2", Toast.LENGTH_SHORT).show();
} else if (copyEntry.getX() == 3.0f && copyEntry.getY() == 3.0f) {
Toast.makeText(MainActivity.this, "3,3", Toast.LENGTH_SHORT).show();
}
}
}
}
isTapped[0] = true;
return false;
}
});
}
@Override
public void onNothingSelected() {
}
});
The code snippet above let me work with the Entry
object which was associated with the point that was double tapped. Also, I have set a range of 100 pixels while the point was double tapped for the convenience of fat-finger tapping.
I'd love to know if there is a clean solution for double tapping a value while obtaining its Entry
data.