You need to catch key events on your activity, not your view.

On Mon, Mar 28, 2011 at 3:09 PM, bob <[email protected]> wrote:

> Can someone tell me why the onKeyDown event never gets called here?
> (even when a key is pressed)
>
>
> import android.app.Activity;
> import android.content.Context;
> import android.graphics.Bitmap;
> import android.graphics.BitmapFactory;
> import android.graphics.Canvas;
> import android.graphics.Color;
> import android.os.Bundle;
> import android.view.Display;
> import android.view.KeyEvent;
> import android.view.View;
> import android.view.Window;
> import android.view.WindowManager;
>
> public class Tutorial2D extends Activity {
>
>        public int ctr = 0;
>        Bitmap bkGround;
>        Bitmap _scratch;
>
>
>        /** Called when the activity is first created. */
>        @Override
>        public void onCreate(Bundle savedInstanceState) {
>                super.onCreate(savedInstanceState);
>
>                requestWindowFeature(Window.FEATURE_NO_TITLE);
>                setContentView(new Panel(this));
>                bkGround = BitmapFactory.decodeResource(getResources(),
>                                R.drawable.background_ocean);
>
>                Display display = ((WindowManager)
> getSystemService(Context.WINDOW_SERVICE))
>                                .getDefaultDisplay();
>
>                int wid = display.getWidth();
>                int height = display.getHeight();
>
>                bkGround = bkGround.createScaledBitmap(bkGround, wid,
> height, true);
>
>                _scratch = BitmapFactory.decodeResource(getResources(),
> R.drawable.icon);
>
>
>        }
>
>        class Panel extends View {
>                public Panel(Context context) {
>                        super(context);
>                }
>
>
>            @Override
>            public boolean onKeyDown(int keyCode, KeyEvent msg) {
>                        return false;
>               // return thread.doKeyDown(keyCode, msg);
>            }
>
>
>
>
>
>                @Override
>                public void onDraw(Canvas canvas) {
>
>                        canvas.drawBitmap(bkGround, 0, 0, null);
>
>                //      canvas.drawBitmap(_scratch, ctr % 200, 10, null);
>
>
>
>                        ctr++;
>
>                        invalidate();
>                }
>        }
>
> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
~ Jeremiah:9:23-24
Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to