Android: How to call onTouch only after an OnLongClick?


I have an image, which can be moved around and scaled with pinch gesture.. All this is done inside onTouch(). I want to restrict this and make it movable(and scalable) only after the user has done a longclick on the image.. How do I do this?

Register a LongCLickListener. If a long click is recognized set a flag to true.

In the OnTouch method allow scaling and moving only if the flag is set to true. After the moving and scaling set the flag to false again.

Here is some pseudocode:

public class MyActivity extends Activity {

   private boolean longClick = false;

   public boolean onTouch(View v, MotionEvent event) {
      if (longClick) {
         // do scaling and moving ...
         longClick = false;
      return false;

   public boolean onLongClick(View v) {
      longClick = true;
      return false;