Search code examples
androidgesture

(Android Studio) Please find a solution on my simple code


I wrote quite simple code using a tutorial. But I got an unexpected problem saying

addOnGesturePerformedListener (android.gesture.GestureOverlayView.OnGesturePerformedListener) in GestureOverlayView cannot be applied(com.example.customgestures.CustomGestureActivity)

on below line's 'this'

gOverlay.addOnGesturePerformedListener(this); 

this is my whole code

package com.example.customgestures;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.widget.Toast;
import android.gesture.Gesture;
import java.util.ArrayList;

public class CustomGesturesActivity extends AppCompatActivity {

private GestureLibrary gLibrary;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_custom_gestures);

    gLibrary = GestureLibraries.fromRawResource(this, R.raw.gesture);
    if (!gLibrary.load()) {
        finish();
    }

    GestureOverlayView gOverlay = (GestureOverlayView) findViewById(R.id.gOverlay);
    gOverlay.addOnGesturePerformedListener(this);
}

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture)  {
    ArrayList<Prediction> predictions = gLibrary.recognize(gesture);
    if (predictions.size() > 0 && predictions.get(0).score >1.0) {
        String action = predictions.get(0).name;
        Toast.makeText(this, action, Toast.LENGTH_SHORT).show();
    }
}

}

Can any one help me??


Solution

  • Implement this interface on activity:

     GestureOverlayView.OnGesturePerformedListener
    

    It will solve your problem.