From the course: Android Development: Data Binding
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using converters - Android Tutorial
From the course: Android Development: Data Binding
Using converters
- [Instructor] Sometimes, you need a piece of data to be formatted or somehow modified before displaying it to the user. And for this use case, you can use Converters. Converters are somewhat related to Binding Adapters, except that they are used to modify the display of the data instead of changing it into another type. So for this example, we're going to build a Converter, that takes the temperature value , and converts it into a descriptive string. So in the Binding Adapters folder, let's open up the Converters file. And this file contains a single object that implements a static function called Temp To Description. So it takes an Integer value and returns a String. In this case, the function returns a different String, depending on what range the temperature is in. So for example, the temperature is below zero, we return the String in 0 "Man, it's cold!". Otherwise, we check to see if the temperature is within certain…
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.