Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3602096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:42:12+00:00 2026-05-18T20:42:12+00:00

I was informed in a later answer that I have to add the GestureOverlayView

  • 0

I was informed in a later answer that I have to add the GestureOverlayView I create in code to my view hierarchy, and I am not 100% how to do that. Below is the original question for completeness.

I want my game to be able to recognize gestures. I have this nice SurfaceView class that I do an onDraw to draw my sprites, and I have a thread thats running it to call the onDraw etc .

This all works great.

I am trying to add the GestureOverlayView to this and it just isn’t working. Finally hacked to where it doesn’t crash but this is what i have

public class Panel extends SurfaceView implements SurfaceHolder.Callback,         OnGesturePerformedListener  
{ 
public Panel(Context context)
{
    theContext=context;
    mLibrary = GestureLibraries.fromRawResource(context, R.raw.myspells);
    GestureOverlayView gestures = new GestureOverlayView(theContext);       
    gestures.setOrientation(gestures.ORIENTATION_VERTICAL);
    gestures.setEventsInterceptionEnabled(true);
    gestures.setGestureStrokeType(gestures.GESTURE_STROKE_TYPE_MULTIPLE);

    gestures.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));

    //GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
    gestures.addOnGesturePerformedListener(this);
 }
 ...
 ...
 onDraw...
surfaceCreated(..);
...
...


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

  // We want at least one prediction
  if (predictions.size() > 0) {
   Prediction prediction = predictions.get(0);
   // We want at least some confidence in the result
   if (prediction.score > 1.0) {
    // Show the spell    
     Toast.makeText(theContext, prediction.name, Toast.LENGTH_SHORT).show();
   }
  }
 }


}

The onGesturePerformed is never called. Their example has the GestureOverlay in the xml, I am not using that, my activity is simple:

   @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    Panel p = new Panel(this);
    setContentView(p);
}

So I am at a bit of a loss of the missing piece of information here, it doesn’t call the onGesturePerformed and the nice pretty yellow “you are drawing a gesture” never shows up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:42:13+00:00Added an answer on May 18, 2026 at 8:42 pm

    This was a major pain but I finally figured out the solution. There is absolutely no good documentation on this anywhere online. I finally got it work work by using something called a “FrameLayout” and then adding both the surfaceview and the gesture view there. Once you do that, you set the FrameLayout as your content view.

    Unfortunately, the above solution offered by RomanGuy didn’t seem to work (or possibly, I just couldn’t get it to work) for some reason. There is no .addView() function available for the SurfaceView class like there is for a regular view. That function exists for ViewGroups and will work fine for adding gestures on anything other than a surfaceview I think.

    Your activity must implement the OnGesturePerformedListener interface for this to work.

    You can see the full tutorial and source code on my website here: http://scanplaygames.com/?p=193

       package view.stack;
    
    import game.core.GameView;
    
    import java.util.ArrayList;
    import android.app.Activity;
    import android.gesture.Gesture;
    import android.gesture.GestureLibraries;
    import android.gesture.GestureLibrary;
    import android.gesture.GestureOverlayView;
    import android.gesture.Prediction;
    import android.gesture.GestureOverlayView.OnGesturePerformedListener;
    import android.os.Bundle;
    import android.view.SurfaceView;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.view.Window;
    import android.widget.FrameLayout;
    import android.widget.Toast;
    
    public class GestureActivity extends Activity implements OnGesturePerformedListener 
    {
        protected GameView surfaceView;
        protected GestureOverlayView gestureOverlayView;
        protected GestureLibrary mLibrary;
        protected FrameLayout frameLayout;
    
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
    
            gestureOverlayView = new GestureOverlayView(this); 
            surfaceView        = new GameView(this);            
            frameLayout        = new FrameLayout(this);
    
            //gestureOverlayView.addView(surfaceView);    
            gestureOverlayView.setOrientation(gestureOverlayView.ORIENTATION_VERTICAL);
            gestureOverlayView.setEventsInterceptionEnabled(true);
            gestureOverlayView.setGestureStrokeType(gestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE);
    
            mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
            gestureOverlayView.addOnGesturePerformedListener(this);
    
            frameLayout.addView(surfaceView, 0);
            frameLayout.addView(gestureOverlayView,1);
    
            setContentView(frameLayout);
        }
    
        @Override
        public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) 
        {
            // TODO Auto-generated method stub
            ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
    
            // one prediction needed
            if (predictions.size() > 0)
            {
                Prediction prediction = predictions.get(0);
    
                // checking prediction
                if (prediction.score > 1.0) 
                {
                    // and action
                    Toast.makeText(GestureActivity.this, prediction.name,
                            Toast.LENGTH_SHORT).show();
                }
            }
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was informed in a later answer that I have to add the GestureOverlayView
in an answer to this question I have been informed that my problems lie
My DBAs have informed me that one of my applications is really bogging down
My hosting service just informed me that they don't have Git installed on any
i am an amateur website developer and am not that informed on the differences
Edit: tchrist has informed me that my original accusations about Perl's insecurity are unfounded.
I have just been informed that a Rails 3 project I've been working on
Let's pretend that I have a site where the users create topics and write
I have just been informed that the Silverlight 4 Toolkit (latest download) requires the
I've just been informed at my workplace that we have an application that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.