Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android databinding. How to set layout xml file for generated *Binding class

Let's assume I have my layout file myview.xml which created with databinding in mind. Then android will generate MyViewBinding class for me. And in some examples I saw code like this:

MyViewBinding mbinding = DataBindingUtils.inflate(inflatter, R.layout.myview, parent, false)
/// using mbinding somehow.

However if I don't want to use DataBindingUtils and wan't to use MyViewBinding directly I'm facing with the problem. MyViewBinding.inflate have different signature than DataBindingUtils.inflate and don't accept layout id (in this example it's R.layout.myview) as parameter.

So my question is - if I'm using generated binding class like MyViewBinding how could I say it which layout file it should use?

like image 588
silent_coder Avatar asked Nov 20 '25 19:11

silent_coder


1 Answers

The binding class name is generated from the layout file. There is a 1-1 mapping between the layout file and the binding class so when you use MyViewBinding.inflate, it will use R.layout.my_view.

like image 80
yigit Avatar answered Nov 22 '25 07:11

yigit



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!