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: Use a custom component

Anko layouts: Use a custom component

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

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…

Contents