Here's the code:
private lateinit var binding: ResultProfileBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ResultProfileBinding.**inflate(layoutInflater)**
val view = binding.root
setContentView(view)
}
Why layoutInflater? Isn't inflate
supposed to inflate an xml file?
Doing a Ctr Q on inflate
gives this public static @NonNull com.example.ActivityMainBinding inflate(@NonNull android.view.LayoutInflater inflater)
I can't find this function on the android developer website. It's either in LayoutInflater or View. Where can you find this function?
CodePudding user response:
Isn't inflate supposed to inflate an xml file?
Yes. A LayoutInflater
inflates layout resources.
I can't find this function on the android developer website
It is code-generated in your project. That generated code is not significantly different than if you had typed it in yourself, which is why it uses a LayoutInflater
to inflate the associated layout resource.
Where can you find this function?
On your computer. Specifically, it will be in one of the subdirectories off of your module's build/
directory.