I just tried by copy and pasting your source code in a new Android project using the Eclipse plugin and it works just fine.
On Sun, May 17, 2009 at 1:38 PM, klirr <[email protected]> wrote: > > added setFocusable(true); but still doesn't work. > > > package com.android.shmup; > > import android.app.Activity; > import android.content.Context; > import android.graphics.*; > import android.os.Bundle; > import android.view.View; > import android.view.KeyEvent; > import android.view.View.OnKeyListener; > > public class Shmup extends Activity { //GraphicsActivity { > > �...@override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(new GameView(this)); > } > > private static class GameView extends View implements > OnKeyListener { > private Paint mPaint = new Paint(); > private int x; > private int y; > > public GameView(Context context) { > super(context); > x = 135; > y = 303; > setOnKeyListener(this); > setFocusable(true); > requestFocus(); > } > > �...@override > protected void onDraw(Canvas canvas) { > Paint paint = mPaint; > canvas.translate(10, 10); > canvas.drawColor(Color.rgb(184,134,11)); > paint.setColor(Color.rgb(107,142,35)); > paint.setStrokeWidth(1); > canvas.drawRect(x,y,x+30,y+7,paint); > canvas.drawRect(x+10,y+7,x+20,y+27,paint); > canvas.drawRect(x+5,y+27,x+25,y+32,paint); > } > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > // if (keyCode == KeyEvent.KEYCODE_M) { > // x = 145; > // y = 100; > // this.invalidate(); > // } > x = 145; > y = 100; > //this.invalidate(); > invalidate(); > return true; > } > > public boolean onKey(View v, int keyCode, KeyEvent event) { > x = 145; > y = 100; > v.invalidate(); > this.invalidate(); > return true; > } > > } > > } > > > > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

