AlertDialog vs AlertDialog.Builder

Why not use the AlertDialog.Builder class, and not the methods available directly to AlertDialog example, why use AlertDialog.Builder.setCancellable and not AlertDialog.setCancellable ? Is this a case of redundancy?

+6
source share
4 answers

Since AlertDialog.setCancellable returns void, and AlertDialog.Builder.setCancellable returns AlertDialog.Builder .

This means that the builder allows you to group a bunch of settings with a bit less granularity. It’s just a convenience class.

+5
source

AlertDialog allows you to show a dialog over your activity / fragment. It is usually used to prompt the user for interaction, including several buttons, or for something to notify.

AlertDialog.Builder is the internal static class AlertDialog, which allows you to quickly configure the dialog using its convenient methods. Its just like a helper class for AlertDialog. It is used to call methods in a chain.

+7
source

AlertDialog.Builder performs attribute settings such as setTitle() or setMessage() and is not displayed to the user.

AlertDialog is one that displays the attributes that were set in AlertDialog.Builder .

The goal of having as mentioned somewhere, is that it allows you to set the settings separately from the actual display, which, in turn, makes a convenient thing.

+1
source

I think factory methods are more convenient.

0
source

Source: https://habr.com/ru/post/912431/


All Articles