From the course: Android Development Essential Training: 3 Navigation
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Handle view events with lambdas - Android Tutorial
From the course: Android Development Essential Training: 3 Navigation
Handle view events with lambdas
- [Instructor] Kotlin's lambdas allow us to remove the extra boilerplate that we typically encounter with Java callback methods. Lambdas are basically anonymous functions without a name. They allow us to really focus on the code that we care about. As an example, we're going to add an on-click listener to the FAB here that's seen on our home screen. Currently when we click on it, nothing happens. Instead, we'll move over to Android Studio to display a snackbar when the click event occurs. We'll access the FAB from the binding class and then we'll call its setOnClickListener method. Let's do that at the end of the onCreate function starting here on line number 19. We'll get access to her binding, then our FAB. And from here, we're going to call its setOnClickListener method. This method takes an anonymous function that implements the View.OnClickListener interface. This interface has one abstract method, OnClick. So you…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Handle view events with lambdas3m 35s
-
(Locked)
Explore ViewModels and LiveData3m 11s
-
(Locked)
Add a ViewModel to an Activity4m 15s
-
(Locked)
Store and publish data in a ViewModel3m 22s
-
(Locked)
Subscribe to changes in LiveData values5m 11s
-
(Locked)
✓ Challenge: Take my order2m 9s
-
(Locked)
✓ Solution: Take my order2m 29s
-
(Locked)
-
-
-