- Messing with XML
- Binding Views to the activity
- Understand how to set an activity layout
- Understnd how to initialize a view
- Using the OnClickListener interface for buttons and dialogs
- Creating a Dialog
Drag and drop the button onto the xml layout. Or manually code it in the xml code (Better).
Make sure you give the views an id so we can use them later in the code!
Red Arrow: We set the layout of the activity to activity_main.xml
Green Arrow: We initialize the view by finding the id.
Now it's time to use the OnClickListener Interface for the Button.
This is how it looks like.
Now when you click on the button, lets do something to the text while we are at it.
Lets create a Messagebox too!
With messageboxes there is this class called a AlertDialog.
We will have to use it's Builder subclass to edit upon the dialog.
Take a look at how it's done.
Now the 2nd paramater to positiveButton is null, if you want you can implement another OnClickListener when the user clicks OK. Try messing with icon and setNegativeButton