API or method to convert gesture to text in android

This question already has an answer here:

  • Fling gesture detection on grid layout 18 answers

  • You can use a GestureDetector that generates String when a gesture is detected.

    For example use OnGestureListener callbacks :

    // From inside some Context (View, Activity, ...)
    GestureDectector detector = new GestureDetector(this, new OnGestureListener() {
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            gestureDetected("FLING"); // 'gestureDetected' is then a callback to invoke on 'conversion of a gesture into a string'
        }
    });
    

    Then MotionEvent have to be 'forwarded' to the GestureDetector , for example by overriding View.onTouchEvent(MotionEvent) :

    public boolean onTouchEvent(MotionEvent event) {
        return detector.onTouchEvent(event);
    }
    
    链接地址: http://www.djcxy.com/p/91210.html

    上一篇: 如何获得在Android的触摸位置?

    下一篇: 在android中将手势转换为文本的API或方法