
- This event has passed.
12 PM – Android Game Dev – Gamas
June 10, 2023 @ 12:00 pm - 1:00 pm
Homework
- In the MainActivity.java, if the user forgot to put either player1 name or player2 name. Prevent user from starting the game. You need to display an Android alert.
- Example on how to user Android alert:
// import the necessary libraries import android.app.AlertDialog; import android.content.DialogInterface; // in your activity or fragment AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Sample Alert"); builder.setMessage("This is a simple alert box"); // Add the buttons builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); // Create the AlertDialog AlertDialog dialog = builder.create(); // show the dialog dialog.show();