Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does description of `container parameter for function onCreateView of fragment class` mean?

The description of container parameter for function onCreateView of fragment class says :

container : If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view.

does the line

The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view

mean that container.addView(some_view) is not permitted?

like image 213
ThinkingMonkey Avatar asked Dec 06 '25 14:12

ThinkingMonkey


1 Answers

Correct. You would use this parameter in a call to inflate() on a LayoutInflater (e.g., inflater.inflate(R.layout.frag, container, false);) or to determine what LayoutParams are needed if you are creating your fragment contents directly via Java instead of inflation. Otherwise, the container is owned by the hosting activity, and your fragment should leave it alone, AFAIK.

like image 175
CommonsWare Avatar answered Dec 08 '25 04:12

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!