0% found this document useful (0 votes)
7 views1 page

Theory 2

Mobile development for beginners

Uploaded by

cvlnpsg987
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Theory 2

Mobile development for beginners

Uploaded by

cvlnpsg987
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

onClick(View v) Method:

• 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: AlertDialog.Builder is a helper class used to build an


AlertDialog. It allows you to set various properties of the dialog, such as the title,
message, and buttons, before displaying it.
3. new AlertDialog.Builder(MainActivity.this):

• Context: MainActivity.this refers to the current activity (MainActivity).


This provides the context needed to display the dialog within the current activity's UI.
• AlertDialog.Builder: This creates a new instance of AlertDialog.Builder, which
you'll use to con gure the dialog.
4. setTitle("Dialog Title"):

• 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

You might also like