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

Handle view events with lambdas - Android Tutorial

From the course: Android Development Essential Training: 3 Navigation

Start my 1-month free trial

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…

Contents