Articles → ANDROID → AlertDialog in android

AlertDialog in android






What is alertdialog?





Regions of alertdialog










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