From the course: Intermediate Kotlin for Android Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Anko layouts: Listeners
From the course: Intermediate Kotlin for Android Developers
Anko layouts: Listeners
- [Instructor] Anko provides you with the ability to connect various listeners to your layout code. Let's see that in action. The first thing we need is the dependency for the Anko coroutine's SDK. That's here on line 38. Just like with the layout support above it, the number that you provide behind the SDK artifact is based on our min SDK version for the application, so that's why we're using SDK 21 dash coroutines. Now, let's move over to our Anko component so that we can add our first listener. What we want is when someone clicks on a planet's description text, then we're going to show them a toast message. So, the first thing we want to do is come to line 20 and add a little bit of space for ourselves. And then we're going to call into the onClick function. Next, we're going to use toast and we're just going to put a simple message. Hey world from Anko. Now, how is it that we can include this on click listener here inside of our Anko DSL? Well, just like with most things in…
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
-
-
-
-
-
Anko overview3m 33s
-
(Locked)
Anko commons: Basics4m 12s
-
(Locked)
Anko commons: Design and support.v43m 55s
-
(Locked)
Anko layouts: Basics3m 1s
-
(Locked)
Anko layouts: Create a custom component6m 2s
-
(Locked)
Anko layouts: Style component views4m 18s
-
(Locked)
Anko layouts: Use a custom component4m 16s
-
(Locked)
Anko layouts: Listeners4m 28s
-
(Locked)
Anko layouts: Anko Support plugin1m 54s
-
-
-
-