I programmed a simple game using SurfaceView. I only started learning how to program for 2 months now so don't really know how to make buttons that can control my game, such as when the player dies there will be a "Restart" button. Would it be easiest to do it in XML or programmatically? Should it be in my MainActivity or in my SurfaceView?
public class MainActivity extends Activity
{
GamePanel Panel;
RelativeLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Panel = new GamePanel(this);
/*
all my code for ads
*/
layout = new RelativeLayout(this);
layout.addView(Panel);
layout.addView(adView);
setContentView(layout);
}
Add your button via XML. Using game state you can set the button visible or invisible. From my experience, user interaction is best kept in Activities.