I am creating custom arc views, which is like rainbow views. I can draw arc views but I am unable to create separate click events for each view. How to set separate click events
A bit of a workaround, but it works. Put this inside ArcView
:
@Override
public boolean performClick() {
return super.performClick();
}
@Override
public boolean onTouch(View view, MotionEvent event) {
view.performClick();
if (isPointInCircle((int) event.getX(), (int) event.getY())) {
// do what you want to do and get rid of the next two lines
String color = (((ArcView) view).color == Color.RED) ? "RED" : (((ArcView) view).color == Color.BLACK) ? "BLACK" : "BLUE";
Toast.makeText(context, color, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
private boolean isPointInCircle(int clickX, int clickY) {
return (clickX - x) * (clickX - x) + (clickY - y) * (clickY - y) <= radius * radius;
}
Note that for the Toast
to work, you need to make context
global, but most likely you will want to get rid of the Toast
anyway.