To Lecture Notes
TempConverter Example
Goal:
- Convert a Celsius Temperature to Fahrenheit using three different methods to set up
the button event handler.
Directions:
- Create an Android Studio project with the name TempConverter.
- Method 1: Define an onClick property in the
Button widget.
Use these layout and Java activity files:
activity_main.xml
MainActivity.java
- Method 2: Define a private OnClickListener class for the event
handler.
Replace the layout and Java activity files with these files:
activity_main.xml
MainActivity.java
- Method 3: Use a private anonymous class to define the event handler.
Use the same layout file; use this Java activity file:
MainActivity.java
- Method 4: Pass a lambda function click handler
to the convert.setOnClickListener method.
Use the same layout file; use this Java activity file:
MainActivity.java