0

I'm creating an imageview in Android and try to make it movable by user's fingers.

I need to handle 2 events, one is when I want to move the ImageView and the other is to long click on it.

However, I'm facing an issue that when I'm moving the ImageView, my finger is always on the screen. It also means that setOnClickListener() will be called. Therefore, I cannot do my will on setOnClickListener while moving the object.

I would like to have your suggestion and consult. If possible, I would specially appreciate you.

Long Uni
  • 101
  • 3
  • 12

1 Answers1

0

See MotionEvent:

onTouchEvent(MotionEvent touchevent) 

There are several actions defined to distinguish between event, e.g. ACTION_MOVE or ACTION_DOWN. See this example:

public boolean onTouchEvent(MotionEvent touchevent) 
{
  switch (touchevent.getAction())
  {
     case MotionEvent.ACTION_DOWN: 
     {
         ...
         break;
     }
     case MotionEvent.ACTION_UP: 
     {
         ...

Find another example here:

view.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        // do something
        break;
    case MotionEvent.ACTION_MOVE:
        // do something else
        break;
    }
    return false;
  }
});
Community
  • 1
  • 1
Trinimon
  • 13,839
  • 9
  • 44
  • 60