【发布时间】:2020-08-03 14:55:24
【问题描述】:
我的 android 项目中有一个自定义视图,MyCustomView。
通过像按钮这样的内置视图,我可以使用数据绑定库将回调函数传递给按钮:
<Button
...
android:onClick="@{() -> viewModel.donePressed()}" />
如何通过 XML 传递可以在 MyCustomView 类中访问的回调函数?
我希望它看起来像这样:
<MyCustomView app:onFinish="@{() -> viewModel.finish()}" />
然后在MyCustomView 类中(扩展LinearLayout)我需要调用onFinish 变量。
感谢您的任何想法。
【问题讨论】:
标签: android android-custom-view android-xml android-custom-attributes