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 trialRifqi Fahmi
23,164 Pointswhy inflate has 3 argument ? what is the different from DayAdapter
In this recyclerView Hour adapter we see ben use inflate method with 3 argument that is
.inflate(R.layout.hourly_list_item, parent, false);
I see that in the day adapter ben use inflate method with 2 argument that is
.inflate(R.layout.custom_daily_list, null);
I didn't know the difference between this 2 inflate method since ben just say you must use it. Anyone know the difference ??
2 Answers
Rifqi Fahmi
23,164 Pointsdoes it have significant meaning for the layout ?? Cause I try to change the parent to null and the hour adapter still works fine.
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_hour_list, null);
I also change the daily adapter to use the parent view and it also still works fine
convertView = LayoutInflater.from(mContext).inflate(R.layout.custom_day_list, parent, false);
what happen here?
Ben Deitch
Treehouse Teacher.inflate(R.layout.hourly_list_item, parent, false);
Inflate the R.layout.hourly_list_item View. Use the parent View to choose the right type of LayoutParams for our new View, but don't attach this new View to the parent.
.inflate(R.layout.custom_daily_list, null);
Inflate the R.layout.custom_daily_list View, and don't give it a parent.
Here's the LayoutInflator docs if you'd like to investigate anything yourself :)