androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

How do I call a ViewBinding for a ViewGroup in an Activity or fragment? #68

Closed lhjgege closed 3 years ago

lhjgege commented 3 years ago

How do I call a ViewBinding for a ViewGroup in an Activity or fragment?

kirich1409 commented 3 years ago

I need more context about the question. Can you show code where you want to apply VBPD?

lhjgege commented 3 years ago

example,I use it in an activity or fragment LayoutInflater.from(requireContext()).inflate(R.layout.my_study_header, null),How did you get it viewbinding?

kirich1409 commented 3 years ago

You can use

private val viewBinding: ProfileBinding by viewBinding(createMethod = CreateMethod.INFLATE)

to inflate and create a ViewBinding from you layout. Just replace ProfileBinding with binding for the R.layout.my_study_header layout (it must be called MyStudyHeader) and don't forget to set root view of the iew binding to activity or fragment