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 - Android Tutorial
From the course: Android Development Essential Training: App Architecture with Kotlin
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
-
-
-
-
(Locked)
Work with synthetic view bindings5m 10s
-
(Locked)
Get view references with findViewById()4m 53s
-
(Locked)
Handle view events with lambdas5m 26s
-
(Locked)
Create companion object functions6m 16s
-
(Locked)
Update display from new data4m 47s
-
(Locked)
Restore state after orientation change7m 10s
-
(Locked)
Add a ViewModel to an activity4m 43s
-
(Locked)
Subscribe to changes in LiveData values7m 57s
-
(Locked)
-
-
-