Reputation: 1834
Could someone explain the dot notation used below. Is that a single or several statements or shorthand for something else?
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("ALERTTILESTRING")
.setMessage("alertNameString")
.setCancelable(false)
.setNegativeButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
Upvotes: 0
Views: 275
Reputation: 152
It's just a shorthand for all the methods called on the AlertBuilder object builder. It's the same as:
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("ALERTTILESTRING");
builder.setMessage("alertNameString");
builder.setCancelable(false);
builder.setNegativeButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
Upvotes: 4
Reputation: 317692
That's the Builder Pattern implemented in Java. All that's happening here is that the builder object of type AlertDialog.Builder is being returned from each method called on it, so you can chain the calls together in sequence. In your example, it's no different if you just called the same methods repeatedly on the builder
instance. But that would be more typing.
Upvotes: 4