[Android] Display Yes/No Alert box using java.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Do this action");
builder.setMessage("do you want confirm this action?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do do my action here
dialog.dismiss();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// I do not need any action here you might
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
In the following line, remember to specify your class.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
For example it should change like this.
AlertDialog.Builder builder = new AlertDialog.Builder(ClassName.this);
Comments
Post a Comment