7

How to get click position with onClickListener? Like follow in onTouchListener.

      int x = (int)event.getX();
      int y = (int)event.getY();
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
NrNazifi
  • 1,621
  • 3
  • 25
  • 36

1 Answers1

8

Use an onTouchListener with ACTION_DOWN flag

view.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN){
                int x = (int) event.getX();
                int y = (int) event.getY();
            }
            return true;
        }
    });
endian
  • 4,761
  • 7
  • 32
  • 54
  • 1
    The behavior from this is far from onClickListener. A `Floating Action Button` (for instance) click event is very different from a touch down event. – Gustavo Maciel Nov 03 '15 at 02:06
  • 11
    Click is a combination of an `ACTION_DOWN` with `ACTION_UP` within a certain amount of time and without moving "a lot". So this doesn't answer the question. – AlikElzin-kilaka Dec 23 '15 at 07:21