有没有办法将绑定附加到 setContentView activity
Is there a way to attach bindings to a setContentView activity
目前,如果我想要附加绑定,我会这样做
DataBindingUtil.setContentView(this, R.layout.main_activity);
我在使用需要调用
的自定义第三方 Activity 时遇到问题
setContentView(R.layout.main_activity);
如何将绑定附加到布局设置为 setContentView
的 activity
您需要先扩充布局,调用 setContentView(inflatedView)
并设置 DataBinding:
/* I don't know if passing 'null' as parent breaks something in your layout, I tested it in
mine and it did work.*/
View rootView = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
setContentView(rootView);
ActivityMainBinding binding = DataBindingUtil.bind(rootView);
目前,如果我想要附加绑定,我会这样做
DataBindingUtil.setContentView(this, R.layout.main_activity);
我在使用需要调用
的自定义第三方 Activity 时遇到问题setContentView(R.layout.main_activity);
如何将绑定附加到布局设置为 setContentView
您需要先扩充布局,调用 setContentView(inflatedView)
并设置 DataBinding:
/* I don't know if passing 'null' as parent breaks something in your layout, I tested it in
mine and it did work.*/
View rootView = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
setContentView(rootView);
ActivityMainBinding binding = DataBindingUtil.bind(rootView);