android data binding with a custom view

In your Custom View, inflate layout however you normally would and provide a setter for the attribute you want to set: private MyCustomViewBinding mBinding; public MyCustomView(…) { … LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mBinding = MyCustomViewBinding.inflate(inflater); } public void setMyViewModel(MyViewModelObject obj) { mBinding.setMyViewModel(obj); } Then in the layout you use it in: <layout xmlns…> <data> … Read more

Android Custom View Constructor

You don’t need the first one, as that just won’t work. The third one will mean your custom View will be usable from XML layout files. If you don’t care about that, you don’t need it. The fourth one is just wrong, AFAIK. There is no View constructor that take a Map as the third … Read more