Wednesday, July 6, 2011

AlertDialogs in Android

In this article we will see how to display an alert dialog. Alert dialogs are more useful when you want to display any validation errors, display any messages etc..

Steps:
  • Use AlertDialog.Builder API to create/build your custome alert dialog.
  • Explore the api of AlertDialog.Builder. There are lot of customizations possible. Some listed here
Source Code

if(validationError){ // Just an example.
new AlertDialog.Builder(MyActivity.this)
.setTitle("Error")
.setMessage("Please enter valid amount")
.setNeutralButton("Close", null)
.show();
}

Refer AlertDialog.Builder API for more customizations.

Output:
The above code will give you an alert dialog like this.

No comments:

Post a Comment