androidviewlayout-inflaterandroid-inflate

What will if i pass in a null as 2 parameter and true as 3 parameter in inflate method in Android


What will if i pass in a null as 2 parameter and true as 3 parameter in inflate method in Android? I know that if i do something like this:

LayoutInflater.from(this).inflate(R.layout.children, parent)

R.layout.children will appear as a children of parent. Did i got it right? But if i pass like this

LayoutInflater.from(this).inflate(R.layout.children, null, false)

It will return me a R.layout.children, without parent, because parent passed as null. But what will if i pass like this?

LayoutInflater.from(this).inflate(R.layout.children, null)

What should R.layout.children as children join? The parents are null, and the third parameter is true by default. That is, there will be an addView implicitly. But to what?


Solution

  • This is the source code for inflate:

        public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) {
            return inflate(resource, root, root != null);
        }
    

    you can see that root is optional and if null the third parameter is false and then no View attached to the parent ViewGroup.