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 Android Lists and Adapters (2015) Custom ListViews getView() and the ViewHolder Pattern

CD Lim
CD Lim
4,782 Points

what is View Group Root?

Hi I would just like to know what is a View Group Root. Ben stated that in creating our inflater

convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null); 

the view group root is set to null and Ben said it is not needed. However, may I ask what is it?

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

The second parameter is an optional view to be the parent of the generated hierarchy. http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(int, android.view.ViewGroup)

So if we specified a ViewGroup for the second parameter, R.layout.daily_list_item would be added as a child to the ViewGroup that we specified. If we leave the second parameter as null, R.layout.daily_list_item would be added as a child to the root ViewGroup which is the top element in the layout.

In this image, the RelativeLayout at top is the root ViewGroup.

CD Lim
CD Lim
4,782 Points

wow thanks for the crystal clear explanation...