alertdialog show in android 1

alertdialog show in android

  AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.do_you_really_want_to_signout));
        builder.setTitle(getResources().getString(R.string.sign_out));
        builder.setCancelable(false);
        builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(AccountActivity.this, R.string.log_out_success,
                        Toast.LENGTH_LONG).show();
               
            }
        });

        AlertDialog alert = builder.create();
        alert.show();

Here is what the above code is Doing:
1. Create an AlertDialog.Builder object.
2. Set the message to display using setMessage() method.
3. Set the title using setTitle() method.
4. Set the icon using setIcon() method.
5. Set the positive button and it’s listener using setPositiveButton() method.
6. Set the negative button and it’s listener using setNegativeButton() method.
7. Create the AlertDialog using create() method.
8. Finally, show the dialog using show() method.

Similar Posts