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

Featured Image

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.

1
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Branko is Inchoo's CTO with over 3 years of active / everyday full time Magento development.

Other posts from this author

Discussion 1 Comment

Add Comment
  1. Kelly Ehret

    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.

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top