Tuesday, July 16, 2024

How To Create a Dialog in Android

 Creating a Dialog is quite easy in Android.

void showDialogToPurchase()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
builder.setMessage("Message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicks OK

}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
        // User cancels the dialog.
             }
            });
builder.create().show();
}