Search code examples
androidandroid-alertdialog

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?


Solution

  • 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