OnGesture Detector

Put your problem here if it does not fit any of the other categories.

OnGesture Detector

Postby uzair77 » Mon May 24, 2010 8:40 am

hi ,
I have Use a Class extends With A button,


I have creating some buttons in my Class which extends Activity


I want to detect Gesture Events only on a Button,
How i implement it,,
uzair77
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Mar 24, 2010 10:57 am

Top

Re: OnGesture Detector

Postby nicholas.hauschild » Tue May 25, 2010 5:27 am

You will need to have an OnGestureListener, and register it within an instance of a GestureDetector. You can call onTouchEvent(MotionEvent) on the GestureDetector to trigger the callbacks that are corresponding to the gesture performed.

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: OnGesture Detector

Postby nicholas.hauschild » Tue May 25, 2010 5:29 am

nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: OnGesture Detector

Postby uzair77 » Tue May 25, 2010 7:34 am

hi nicholas.hauschild

Thanks For Response,,,

GEstureDetector must be implements only with Activity


I have tried to do it
Myclass extends with Button implements with OnGesturelistner

But it not pick any event,,,

Can u give me a little example


Thanks Alot
uzair77
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Mar 24, 2010 10:57 am

Re: OnGesture Detector

Postby nicholas.hauschild » Tue May 25, 2010 1:26 pm

Certainly! I actually use my GestureDetector within a View, take a look at this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyView extends View implements OnGestureListener {
  2.   private GestureDetector gestureDetector;
  3.   public MyView(Context context, AttributeSet attrs) {
  4.     gestureDetector = new GestureDetector(this);
  5.   }
  6.  
  7.   @Override
  8.   public boolean onTouchEvent(MotionEvent event) {
  9.     return gestureDetector.onTouchEvent(event);
  10.   }
  11.  
  12.   //these methods below are required for OnGestureListener implementation
  13.   @Override
  14.   public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  15.                         float distanceY) {
  16.     boolean scrollThing = doScrollThing();
  17.     return scrollThing;
  18.   }
  19.  
  20.   @Override
  21.   public boolean onDown(MotionEvent e) {
  22.     boolean onDownThing = doOnDownThing();
  23.     return onDownThing;
  24.   }
  25.  
  26.   @Override
  27.   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  28.                         float velocityY) {
  29.     boolean onFlingThing = doOnFlingThing();
  30.     return onFlingThing;
  31.   }
  32.  
  33.   @Override
  34.   public void onLongPress(MotionEvent e) {
  35.     doOnLongPressThing();
  36.   }
  37.  
  38.   @Override
  39.   public void onShowPress(MotionEvent e) {
  40.     doOnShowPressThing();
  41.   }
  42.  
  43.   @Override
  44.   public boolean onSingleTapUp(MotionEvent e) {
  45.     boolean onSingleTapUpThing = doOnSingleTapUpThing();
  46.     return onSingleTapUpThing;
  47.   }
  48. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: OnGesture Detector

Postby uzair77 » Mon May 31, 2010 7:22 am

Thanks Alot;
I have implemented it ....
uzair77
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Mar 24, 2010 10:57 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 11 guests