Why would one use the AlertDialog.Builder
class rather than the methods directly available to AlertDialog
,
For example, why use AlertDialog.Builder.setCancellable
rather than AlertDialog.setCancellable
? Surely this is a case of redundancy?
Because AlertDialog.setCancellable
returns void and AlertDialog.Builder.setCancellable
returns an AlertDialog.Builder
.
This means that the builder allows you to chain a bunch of settings with a little less verbosity. It's just a convenience class
AlertDialog allows you to show a dialog above your activity/fragment. It is usually used for prompting user for interaction including few buttons or notifying for something.
AlertDialog.Builder is an inner static class of AlertDialog which allows you to quickly setup a dialog with its handy methods. Its just like a helper class to AlertDialog. It is used for calling methods in a chain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With