Search code examples
androidmotionevent

Using of MotionEvent (ACTION_MOVE)


So I have special question to you: How can I catch buttons when I use move action? How can I handle moves on my screen for buttons(or other elements)?

I used MotionEvent (ACTION_MOVE) but by using that fragment of code i don't get the desired result

in OnCreate

btn1.setOnTouchListener(this); //for all of buttons on Activity

in onTouch

switch(event.getAction()) { 
  case MotionEvent.ACTION_MOVE: 
       //actions
  break;
}

actions will be occur for first button from which the movement starts. In other case nothing will occur

At this time I think that I can use ACTION_MOVE for my Activity not for each button or other elements and save coordinates of buttons(top left and bottom right) to arraylist. And when movement starts I could compare this coordinates and real coordinates of movement. So by that way I could know on which buttons movement was.

Probably I reinvent the wheel. That why I ask for your help)


Solution

  • Would you explain more clear? From what I see you need probably do two things: First add listener to all buttons and let your activity implement onTouchListener.
    Second you need to save initial coordinate for each button in MotionEvent.ACTION_DOWN(if I'm right about syntax).
    This way you will have access to all buttons of yours and you can save their coordinates correctly