我想要在 10 个 Activity 中检测手势。所以我创建了一个实现 OnGestureListener
的类。该类还为 onTouchEvent()
扩展了 GestureDetector
。为了将所有 Activity 连接到此类,我实例化了此手势监听器类。我面临的问题是我无法将上下文(通过其他 Activity 传递给此类)和 this
传递给父类(super class)。这是代码:
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);
}
.....
}
问候
最佳答案
也许更干净的解决方案是为每个 Activity 实例化一个新的 GestureDetector
/GestureReader
。
根据文档,GestureDetector
也会对 Application
的上下文感到满意,因此您可以从您的 Activity 之一检索 Application
将其馈送到检测器
关于java - 将 Activity 连接到 GestureListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17248716/