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

Kevin Perez
PLUS
Kevin Perez
Courses Plus Student 8,180 Points

Didn't understand why we set False in the third parameter

View view =inflater.inflate(R.layout.fragment_list, container, false); Any other example why we should set false at the third parameter? And When we should set True. Thanks for read.

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Setting 'false' there is saying, "Don't add this fragment_list to this container ViewGroup". If it was 'true', it would add the newly inflated 'fragment_list' to the container ViewGroup, which is a problem because the Fragment already handles adding the 'fragment_list' to a parent. So if we set it to 'true', we'd end up having a 'fragment_list' with two different parents which causes an error.

Also, we would almost never pass in 'true' for the third parameter. But that's just because if the third parameter was true we wouldn't need the 3 parameter version of 'inflate'; we could just use the 2 parameter version 'inflate(layout_id, ViewGroup)' which always adds the inflated View to the provided ViewGroup.