From the course: Android Development Essential Training: App Architecture with Kotlin

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: App Architecture with Kotlin

Start my 1-month free trial

Handle view events with lambdas

- [Instructor] Event handlers are incredibly common in Android, whether a system level event like a lifecycle event, or an event triggered by a user gesture, it's up to you to decide what happens when an event occurs. It's very easy to create event listeners in Kotlin. Because Kotlin doesn't require as much boilerplate code as Java, Kotlin developers tend to make less use or external libraries, such as Butterknife that were originally developed to counter Java's verbosity. I'm going to work with this event handler that's already present in my starting application. This is creating a event listener object. Now if this were Java, you might see code that's creating an anonymous object that implements an interface. The interface has a single function which receives a single argument, sometimes known as a functional interface. In Kotlin this code can be shrunk down enormously. Now to see how much it's being shrunk, I'm going to expand it a bit. First I'm going to place the cursor after…

Contents