- Code: Select all
public class HelloView extends View {
public HelloView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p=new Paint();
p.setColor(0xFF800000);
p.setStyle(Paint.Style.STROKE);
canvas.drawLine(10, 10, 40, 40, p);
}
}
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HelloView hv = new HelloView(this);
setContentView(hv);
}
}
My question is how can I implement listen for key Event (say 'press 'j' and my view will scroll up by 10 pixels)?