RizN81 RizN81 - 3 months ago 14
Android Question

how to Recognize the multi stroke gesture in android

This is my code. I want to recognize the multi-stroke gesture in my app but it's not working:

gestureOverlayView.addOnGesturePerformedListener(new OnGesturePerformedListener()
{
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture)
{
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
if (predictions.size() > 0)
{
prediction = predictions.get(0);

if (prediction.score > 1.0)
{

DrawText = prediction.name;
Toast.makeText(testone.this, "You Draw" + DrawText,Toast.LENGTH_LONG).show();
if(DrawText.equalsIgnoreCase("E"))
{
Toast.makeText(testone.this, "Z", Toast.LENGTH_LONG).show();
}
}
}
}
});


but when I go to draw the gesture, it disappears immediately.

This is my xml layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gesture Test"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check"
android:id="@+id/checkit"
/>
<android.gesture.GestureOverlayView
android:id="@+id/GalleryGesture"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:gestureStrokeType="multiple"
android:fadeOffset="1000">
</android.gesture.GestureOverlayView>
</LinearLayout>


I want to recognize the gesture when the user clicks on the Button.

Answer

set android:gestureStrokeType="multiple" indicates used to make gestures to recognize multiple strokes.

See following tutorial

http://developer.android.com/resources/articles/gestures.html