Since Sirlate has answered "Why is this needed?", I'll try to answer the rest of the questions.
Wouldn't the layoutId
tell you everything that you need to know about the location of the layout resource?
No, layoutId
, like other resources' ID is only a number. When you reference it through R.layout.some_layout
, it actually refers back to the ID itself, as a number.
Wouldn't it always be res->layout?
Actually, not! You can put any resources in any folder (as long as inside /res
) even if it's a layout resource. /res/layout/
is just a convenient folder since Android already defines it in the first place. After all, Android will just refer the resources as ID number.
What would you put as the package name?
The package name of the app you want to use the layout, as stated by Sirlate.
Why is this needed?
In addition to Sirlate's answer, if you only have a resource ID, it will be impossible for the OS to decide from which package/app the layout is.