Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public void doSomething(Event event, View view){
  2.  
  3. ...do something
  4.  
  5. //if its onClick event that passed do something will trigger once user clicks it
  6. //if its onLongClick event, the method will trigger for the onLongTap event
  7.  
  8. }
  9.  
  10. public class YourView extends View implements View.OnTouchListener {
  11.  
  12. @Override
  13. public boolean onTouch(View v, MotionEvent event) {
  14. //Here you can check for which movement is being made on a switch pattern.
  15. //You can also call any gesture detector you might have
  16.  
  17. mScaleDetector.onTouchEvent(event);
  18. mRotationDetector.onTouchEvent(event);
  19. mGestureDetector.onTouchEvent(event);
  20.  
  21. final int action = MotionEventCompat.getActionMasked(ev);
  22. switch (action) {
  23. case MotionEvent.ACTION_DOWN:
  24. //Do stuff;
  25. break;
  26. case MotionEvent.ACTION_MOVE:
  27. //Do stuff;
  28. break;
  29. case MotionEvent.ACTION_UP:
  30. //Do stuff;
  31. break;
  32. return false;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement