Articles → ANDROID → Alertdialog In Android

Alertdialog In Android






What Is Alertdialog?





Regions Of Alertdialog


  1. Title
  2. Content area (where message is displayed)
  3. Action buttons (Maximum 3)


Picture showing the action buttons on alert
Click to Enlarge


Example




public void ButtonClicked(View view) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("This is the title");
    builder.setMessage("This is the message");
    builder.setCancelable(false);
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(EditTextDemo.this, "Ok Button Clicked", Toast.LENGTH_LONG).show();
        }
    });
    builder.show();
}




Picture showing output of alert dialog in android
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 24, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250