I have an Activity called GameLoop (class which extends Activity). But instead of using an xml file for the layout, i'm using a class for it, since I want to be able to draw to a canvas. (I've seen on some tutorials this is what you're supposed to do)
The layout class is called GameLoopLayout.
I have a game loop running in the layout class, I can render bitmaps to the screen and control the FPS, everything is fine. But now I want to add a button to it, but since i'm not using an xml layout file, I don't know how to do it. Can anyone help me out please?
What I'm doing atm:
GameLoopLayout:
Button button;
Canvas canvas;
SurfaceHolder surfaceHolder;
public GameLoopActivityLayout(Context context) {
//all necessary initializations here...
button = new Button(context);
button.setEnabled(true);
button.setLeft(10);
button.setTop(20);
}
//render function called during game loop
private void render() {
if (!surfaceHolder.getSurface().isValid())
return;
canvas = surfaceHolder.lockCanvas();
//draw all game objects to canvas...
button.draw(canvas);
surfaceHolder.unlockCanvasAndPost(canvas);
}