Join Joe Marini for an in-depth discussion in this video Solution: Color binding adapter, part of Android Development: Data Binding.
(upbeat music) … - [Instructor] All right. … Let's take a look at how I built my solution. … And again, remember, it's not important for your solution … to match mine. … Okay. … So I chose to solve this problem … by adding a binding adapter, … which I said we were going to use, … and I put it into the existing binding adapters file. … And so what I did was I created a function … named tempToColor, and it takes the view … and it takes the integer for the value, … and you can see that for the binding adapter decoration, … I'm declaring that the adapter is used … when it is applied to the textColor attribute on the view. … So the code itself is pretty straightforward, right? … It fits just a few lines. … So when the temperature is below 15, … the text color is set to the Color.BLUE constant, … and when it's equal to or above 22, I use Color.RED. … And unfortunately there's no predefined color constant … for the orange color. … So I had to make my own, … and I did that by using this RGB function …
Author
Released
11/19/2020Skill Level Intermediate
Duration
Views
Related Courses
-
Android App Development: Communicating with the User
with Joe Marini1h 19m Intermediate
-
Introduction
-
What you should know1m 14s
-
Getting set up1m 37s
-
1. Overview
-
What is data binding?1m 51s
-
Doing things the old way4m 2s
-
Setting up your project1m 19s
-
-
2. Basic Data Binding
-
Create binding layout5m 13s
-
-
3. Layout Expressions
-
4. Binding to Observable Data
-
Overview of observables1m 51s
-
Binding to observables4m 49s
-
Binding to ViewModels6m 25s
-
Using binding adapters7m 19s
-
Two-way binding syntax4m 45s
-
Using converters4m 2s
-
-
Conclusion
-
Next steps1m
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Solution: Color binding adapter