0

I have a activity where I have two imagesViews.

This to imagesViews has onClickListener, because I need to know which imageView was clicked. After when I click choosen picture I get result which picture was clicked.

I Know need the same result but I need to know where exacly I click on this image. I need precise coordinates where this imageView was clicked. I know that in onTouch method I have functions like I need.

Can I change onClick method on onTouch? Or in onClick can get precise coordinates?

Bhavin
  • 6,020
  • 4
  • 24
  • 26
edi233
  • 3,511
  • 13
  • 56
  • 97
  • You can use onTouch event ... refer this link [1]: http://stackoverflow.com/questions/9122679/difference-between-ontouch-and-onclick-android – Nixit Patel Mar 29 '12 at 10:02

3 Answers3

4

There is no need for you to use the onClick event, since you can easily capture the click using the onTouch callback. A click is a sequence of one ACTION_DOWN action, several ACTION_MOVE actions and one ACTION_UP action. These can be acquired using the event.getAction() method. If you get an ACTION_DOWN event and then an ACTION_UP event - it means that the user has just clicked your View. You can also measure time spent between these events to be sure that it was a simple click, not a long one. And, of course, you can use the event.getX() and event.getY() methods to get the exact touch point. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
3

you can use onTouch() method for getting touch coordinates

touchView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        System.out.println("Touch coordinates : " +
            String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
            return true;
    }
});
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
0

onclick cannot do this. You can get them only from an onTouchListener.

a question with this info

Community
  • 1
  • 1
Th0rndike
  • 3,406
  • 3
  • 22
  • 42