From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Customize data bindings with an adapter

Customize data bindings with an adapter

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Customize data bindings with an adapter

- Simple text values can be displayed with data binding expressions in the layout file. More complex assignments though, might require the use of adapter functions. These are top level functions that are associated with your layout file with property names that you assign. If you're programming in kotlin, these functions can be placed in any kotlin file, not necessarily in a class. The classic example of a binding adapter is the dynamic presentation of an image. The image view component has a source attribute that can work directly with a URL or a file, but I'm using the Glide open source library to present my images, and there's no way to call complex kotlin or java code from within the layout. So instead, I'll create a binding adapter function. Now again, you could place these anywhere. I could put them in my global file but I prefer to create a special file just for my binding adapters, and I'll create this under my utilities package. I'll create a new kotlin file, I'll call it…

Contents