Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog vs AlertDialog.Builder

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?

like image 574
stephenfin Avatar asked Apr 04 '12 19:04

stephenfin


2 Answers

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

like image 82
jqpubliq Avatar answered Nov 10 '22 01:11

jqpubliq


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.

like image 25
waqaslam Avatar answered Nov 09 '22 23:11

waqaslam