Search code examples
androidtouchcoordinatesontouchlisteneravatar

How to issue action when touch in specific coordinates on view android


hello everyone I am developing application and I have a girl and boy avatar .. I want to issue action like Alert Dialog if he touch specific coordinates in the avatar how to do that without drawing canvas ?? any help please !!


Solution

  • View YOUR_VIEW = findViewById(R.id.MY_VIEW);
    YOUR_VIEW.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.i("Coordinates:", " X: " + String.valueOf(event.getX()) + " , Y: " + String.valueOf(event.getY()));
            return true;
        }
    });