Open top menu

                                     Alert Dialog

The alert dialog create easily, we are discuss about alert Dialog popup window. The alert dialog used basically two button Yes or NO.

     The used some method type discussing:-

·       setTitle(): -set  title be appear in the dialog.

·       setIcon():- set the icon in alert dialog.

·       setOnclicklistener():-  call back (click event) Mathod in dialog.

·       setMessage():-set message display in the alert dialog.

 

       AlertDialog alertDialog = new AlertDialog.Builder(
                        AlertDialogActivity.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Confirm Delete...");

        // Setting Dialog Message
        alertDialog.setMessage("Are you sure you want delete this?");

        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.alert);

        // Setting OK Button
        alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog closed
                Toast.makeText(getApplicationContext(), "You clicked on OK",                      Toast.LENGTH_SHORT).show();
                }
        });
         // Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener()         {
            public void onClick(DialogInterface dialog, int which) {
            // Write your code here to invoke NO event
            Toast.makeText(getApplicationContext(), "You clicked on NO",                     Toast.LENGTH_SHORT).show();
            dialog.cancel();
            }
        });


        // Showing Alert Message

        alertDialog.show();









Tagged

0 comments