(Android Studio) 请根据我的简单代码找到解决方案
(Android Studio) Please find a solution on my simple code
我使用教程编写了非常简单的代码。但是我遇到了一个意想不到的问题
无法应用 GestureOverlayView
中的 addOnGesturePerformedListener (android.gesture.GestureOverlayView.OnGesturePerformedListener)
(com.example.customgestures.CustomGestureActivity
)
在下一行的 'this'
gOverlay.addOnGesturePerformedListener(this);
这是我的全部代码
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();
}
}
}
谁能帮帮我??
在 activity 上实现此接口:
GestureOverlayView.OnGesturePerformedListener
它将解决您的问题。
我使用教程编写了非常简单的代码。但是我遇到了一个意想不到的问题
无法应用GestureOverlayView
中的 addOnGesturePerformedListener (android.gesture.GestureOverlayView.OnGesturePerformedListener)
(com.example.customgestures.CustomGestureActivity
)
在下一行的 'this'
gOverlay.addOnGesturePerformedListener(this);
这是我的全部代码
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();
}
}
}
谁能帮帮我??
在 activity 上实现此接口:
GestureOverlayView.OnGesturePerformedListener
它将解决您的问题。