AlertDialog
An AlertDialog object represents an Alert Box on the screen.
import android.app.AlertDialog;
import android.content.DialogInterface;
Example:
public void setUpMyAlertYesOrNo()
{
// prepare the alert box
alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("Update From Web?");
// set a positive/yes button and create a listener
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
// do whatever
Toast.makeText(getApplicationContext(), "Your data has been updated.", Toast.LENGTH_SHORT).show();
}
});
// set a negative/no button and create a listener
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
// Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show();
}
});
// display box
alertbox.show();
}