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

Android Build a Weather App Hooking Up the Model to the View Plugging in the Data

Kevin Grifo
Kevin Grifo
9,824 Points

Where does the setWeather method come from?

When binding the currentWeather object Ken uses the statement

binding.setWeather(displayWeather);

I was just curious as to where the setWeather method/function is located. What class? I remember Ken stating that a class is automatically generated when enabling and using Java binding called ActivityMainBinding. Is there where this particular method is located? Any help or clarification would truly be appreciated.

Thanks

Ben Deitch
Ben Deitch
Treehouse Teacher

Hey Kevin! I'm not super familiar with data binding, but you should be able to use CMD or CTRL + B on 'setWeather' to jump you to its declaration.

Boban Talevski
Boban Talevski
24,793 Points

It looks like you are right that it's in that automatically generated class ActivityMainBinding.java. I just couldn't find it to see it (CTRL + B doesn't seem to work). The method name is most likely derived from what we set as a variable name in the layout file, i.e. weather, so the generated method gets named setWeather().

1 Answer

in the first video, where we were creating the edits to the activity_main.xml file, we made this tag:

<variable
            name = "weather"
            type = "com.example.stormy.CurrentWeather"/>

the library generates the needed method calls. We told it to call it "setWeather" when we chose that name to be weather in that xml file.