From PHP/JavaScript to Android, the simple stuff – Yes/No Confirmation Dialog

My apologies for a bit misleading title, as there is no PHP Confirmation dialog as such. More precisely its a analogy of JavaScript confirmation dialog and Android (Java) alternative for the same thing.
Here is a little code snippet that you can use to get the Yes/No dialog in Android and then execute corresponding action based on the users choice.
//...
/**
* START Yes/No Dialog Example
*/
new AlertDialog.Builder(MagentoActivity.this)
.setMessage("Are you sure you wish to delete customer?")
.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Execute some method call
Toast.makeText(MagentoActivity.this, "Delete clicked...", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Execute some method call
Toast.makeText(MagentoActivity.this, "Cancel clicked...", Toast.LENGTH_SHORT).show();
}
})
.show();
/**
* END Yes/No Dialog Example
*/
//...
And here is how this might look in simple JavaScript.
//...
var isConfirmed = confirm("Confirm delete?")
if (isConfirmed) {
alert("Confirmed...")
}
else {
alert("Not confirmed...")
}
//...
That’s it, plain and simple. Cheers.
Published in:
Leave a comment
1 comment
I’m a PHP developer that is transitioning into some Android work as well. Just a note of encouragement to keep posting these snippets! They’re really helpful.