Dialog is a small window that usually does not fill screen.
In this tutorial we'll discuss how to create different types of dialog in Android with example
Alert Dialog
private void showAlertDialogOne() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are You Sure?")
.setPositiveButton("Share", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Do something on Share
Toast.makeText(getApplicationContext(), "You Clicked on Share", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Do something on Cancel
Toast.makeText(getApplicationContext(), "You Clicked on Cancel", Toast.LENGTH_LONG).show();
}
});
builder.show();
}
|
Alert Dialog in Android |
Alert Dialog with Title and Icon
private void showAlertDialogTwo(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Confirm Delete...");
alertDialog.setMessage("Are you sure you want delete this?");
alertDialog.setIcon(R.mipmap.ic_launcher);
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
alertDialog.show();
}
|
Alert Dialog in Android with Title and Icon |
0 comments:
Post a Comment