for example
The alert is shown when a button is clicked
we set its onclick listener
inside the onclcik we write
The alert is shown when a button is clicked
we set its onclick listener
inside the onclcik we write
AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this);
builder.setMessage("do u really want to close this app"); builder.setCancelable(false);
// setCancelble wont allow the back button to work
builder.setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MainActivity.this.finish(); } });
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog a=builder.create();
// a alert dialog is finally created out of builder
a.show();
// then alert dialog is shown
No comments:
Post a Comment