From the course: Intermediate Kotlin for Android Developers
Unlock the full course today
Join today to access over 23,700 courses taught by industry experts.
Anko layouts: Use a custom component
From the course: Intermediate Kotlin for Android Developers
Anko layouts: Use a custom component
- [Instructor] Once you havr your Anko component created, you can start to use it in your Android views. Let's move over to our fragment and wire it up to use your component over its XML layout. So the first thing we want to do is create an instance of our planet detail UI component. Now since we're not going to be using the XML layout anymore, we can actually remove the lines from 22 to 25 because we're not going to be setting the text views by means of the find view by ID call. So instead, we're going to replace it with a private val, and let's call our component UI, and we're going to create it lazily, so that we only create it the first that it's accessed, and then we'll just provide a call to our constructor, PlanetDetailUi. Okay, perfect. So next, we can go ahead and update the onCreateView method. So everything from line 31 all the way down to 38 is no longer needed. So we can simply delete all of this. And for our return value, we're now going to use the view that's generated…
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
-
-
-
-