0

I am developing an android application, in which, I am changing the image continuously in intervals. Before every change, I need to check if touch event has occurred or not? If yes, then which event has occurred, DOWN or UP?

In my search I only found how to add touch event and check which event occurred, but I couldn't find a solution which would enable me to know if event has occurred or not.

Can Someone Help me in this?

rambo
  • 36
  • 6
  • 1
    You may want to check the official documentation about Event Listeners: http://developer.android.com/guide/topics/ui/ui-events.html#EventListeners – Felix G. Feb 15 '16 at 15:12

1 Answers1

1

Copy paste this in your java code

public class yourActivity extends FragmentActivity implements View.OnTouchListener {
ImageView yourpic;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

yourpic = (ImageView) findViewById(R.id.yourpicID);
 yourpic.setOnTouchListener(this);
}

@Override
public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;

switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:                                  
                    break;
                case MotionEvent.ACTION_MOVE:
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                case MotionEvent.ACTION_CANCEL:
                    break;
            }
            break;
}
return true;
}
Lincoln White
  • 639
  • 2
  • 12
  • 29