To create an Android AlertDialog with just a single button we can make use of any one method that is provide i.e. one of setPositiveButton(), setNegativeButton() or setNeutralButton() .

AlertDialog with Single Button
Lets create an example where in we have some Information that has to be displayed to the user in a form of a Dialog, it should have a Dismiss button, when clicked the message must hide.
AlertDialog SnippetAlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Information!");
builder.setMessage("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\n" +
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\n" +
"quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\n" +
"consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\n" +
"cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\n" +
"proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
builder.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"Get Started!",Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
AlertDialog diag = builder.create();
//Display the message!
diag.show();
More Posts related to Android,
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
More Posts:
- [fix] Java JDBC SQLSyntaxErrorException: Unknown database - Java
- New-SPLogFile PowerShell - create new SharePoint log file - SharePoint
- Android: Unknown error code during application install : - Android
- Java JDBC Transition Management using PreparedStatement Examples - Java
- fix macOS: The digital signature on the update is missing or invalid. Ventura - MacOS
- How to redirect SharePoint Site Collection to different URL - SharePoint
- How to lock cells in Microsoft Excel for Mac - Windows
- How to URL Decode a Query String in Python - Python