Question

I have 10 activities in which I want to detect gestures. So I have created a class which implements OnGestureListener. This class also extends GestureDetector for onTouchEvent(). To connect all activities to this class, I instantiate this gesture listener class. The issue that I am facing is I can't pass the context (passes by other activites to this class) and this to super class. here is the code:

public class GestureReader extends GestureDetector implements OnGestureListener{

      public GestureReader(Context con)
  {
    super(con,this); // error here

    contxt= con;
    gestures = new GestureDetector(con,this);
  }

    @Override
public boolean onTouchEvent(MotionEvent me) {
    return gestures.onTouchEvent(me);
}

   .....
}

Regards

Was it helpful?

Solution

Maybe the more clean solution would be to instantiate a new GestureDetector/GestureReader for each activity.

According to doc the GestureDetector would also be happy with the Application's context so you can retrieve the Application from one of your activities to feed it to the detector

OTHER TIPS

you can create base Activity that handles gestures and all your 10 Activities extend this base Activity

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top