Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.