0

Trying to figure out how onTouchEvent(MotionEvent e) works. Just look at this:

public boolean onTouchEvent(MotionEvent e) 
    {

       switch(e.getAction() & MotionEvent.ACTION_MASK)
       {

       case MotionEvent.ACTION_POINTER_DOWN:

         int pX = (int) e.getX(e.getPointerId(e.getPointerCount()-1));


        break;

       }

       return true;
    }

When I run it on my phone and... jump on the screen with my fingers very quickly, it crashes. Log says that pointerIndex is out of range but how is that possible? Maybe the value of e.getPointerCount() is updated very slowly? What is wrong? Thanks.

T.Vert
  • 279
  • 2
  • 13
  • what do you really want to do? – Prinz Km Jan 12 '15 at 17:59
  • well, initially there were a lot of code, but it crashed. i'd been reducing it to find a problem until i got to this simple code and it doesn't work either. okay, for example, i want to get the X coord of every new touch. i don't understand why it crashes when i make a lot of touches in a sec – T.Vert Jan 12 '15 at 18:04
  • e.getX(e.getPointerId(e.getPointerCount()-1)) is wrong ? I might have mixed up ID and Index, although i read about it carefully – T.Vert Jan 12 '15 at 18:08
  • if you want to use only single touch, use event.getActionMasked and write cases for ACTION_DOWN,ACTION_MOVE,ACTION_UP. – Prinz Km Jan 12 '15 at 18:16

0 Answers0