The thing is: AlertDialog.Builder()
is something known as a Builder Pattern. It helps to create objects, in our case AlertDialog(s). Now when you want to view method signature of an Android method or function like setContentView()
, you can do so by using Ctrl+Click or Command+Click. You will then be able to view what arguments or parameters to pass to the method.
For Builder however, you chain a series or methods on the builder itself, like:
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // getActivity() when you are on a Fragment, ActivityName.this when you are on an Activity
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
// 3. Get the AlertDialog create()
AlertDialog dialog = builder.create();
// 4. Show the dialog
dialog.show()
Read more about Alert Dialogs on the official documentation.