Theory 2
Theory 2
• Purpose: This method is an event handler that gets called when the associated view (like a
button) is clicked. The View v parameter represents the view that was clicked.
2. AlertDialog.Builder Class:
• Purpose: Sets the title of the AlertDialog. This is the text that appears at the top of the
dialog.
• Example: "Dialog Title" will be the title displayed in the dialog.
5. setMessage("This is a simple dialog message."):
• Purpose: Sets the message or content of the dialog. This is the main text displayed in the
body of the dialog.
• Example: "This is a simple dialog message." is the message that will
be shown to the user.
6. setPositiveButton("OK", null):
• Purpose: Adds a positive button to the dialog. This button is typically used to con rm an
action.
• Text: "OK" is the label of the button.
• Listener (null): The null here means no additional action will be taken when the button
is clicked; the dialog will simply close. However, you could pass an OnClickListener
to handle speci c actions when the button is clicked.
7. setNegativeButton("Cancel", null):
• Purpose: Adds a negative button to the dialog. This button is typically used to cancel or
dismiss the dialog without con rming an action.
• Text: "Cancel" is the label of the button.
• Listener (null): Similar to the positive button, null means no speci c action will be
taken other than closing the dialog. You could provide an OnClickListener if you
want to handle the "Cancel" button click differently.
8. show():
• Purpose: Finally, the show() method is called to display the AlertDialog on the
screen. Without this, the dialog would be created but not shown.
fi
fi
fi
fi
fi