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

Anko layouts: Listeners

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

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…

Contents