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

Saul Glasman
Saul Glasman
18,284 Points

Different ways of getting a binding object

I'm in the middle of the new "Android lists and adapters" course and I'm working through my confusion around the different objects involved in setting up a RecyclerView. The line of code I'm finding the most difficult is

        HourlyListItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                R.layout.hourly_list_item, parent, false);

in the onCreateViewHolder method in the HourlyAdapter. I understand that it's necessary to get an HourlyListItemBinding object to make the hour data show in the list item, but I don't understand why this "inflate" method is the way to do it. For example, in the HourlyForecastActivity, we get a binding object using DataBindingUtil.setContentView instead. What's the difference between these two situations?