在绘制GestureOverlayView时打开第二个Android活动?

时间:2015-06-19 08:01:13

标签: android gesture

我有MainActivity2来实现OnGesturePerformedListener,但我无法开始第二项活动。我错过了什么?

public class MainActivity2 extends Activity
        implements OnGesturePerformedListener
{
    private GestureLibrary gestureLib;

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

        gestureLib = GestureLibraries.fromRawResource(this, 
                R.raw.gestures);
        if (!gestureLib.load()) {
            finish();    
        }
        GestureOverlayView gestures = (GestureOverlayView) 
                findViewById(R.id.gestureOverlayView);
        gestures.addOnGesturePerformedListener(this);
    }

    @Override
    public void onGesturePerformed(GestureOverlayView overlay, 
            Gesture gesture) {    
        ArrayList <Prediction> predictions = gestureLib.recognize(gesture);

        if (predictions.size()>0) {
            Prediction prediction = predictions.get(0);
            if (prediction.score>1.0) {
                if (prediction.name.equals("One")) {
                    Intent intent = new Intent(
                            MainActivity2.this, 
                            MainActivity3.class);
                    startActivity(intent);
                }

                if (prediction.name.equals("Two")) {
                    Intent intent = new Intent(
                            MainActivity2.this,
                            MainActivity4.class);
                    startActivity(intent);
                }
            }
        }
    }
}

0 个答案:

没有答案