Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Where does the weather.formatted time attribute come from?
I've watched the video's a couple of times now. but formattedTime is never declared anywhere (only a method 'getFormattedTime'). So how does the binding know what formattedTIme is?
Ken AlgerTreehouse Teacher
This is a great question.
If we take a look inside
activity_main.xml we have defined a variable,
weather that accesses the
CurrentWeather.java class. This is how we are able to get data from there with things like
weather.temperature. The data binding library translates the
Getters (getTime(), getTemperature(), etc) from the class. Since we defined our own function to return time in a specific format in
getFormattedTime(), the data binding library allows us to get that information in the layout with our defined variable name and the data item we want, with dot notation. Therefore, we can access our formatted time value in the layout with
I hope that makes sense. Please post back if it does not.
Ken W. Alger