包装视图中的Android数据绑定自定义视图

问题描述

好吧,这应该很有趣...

我们有一个带有视图模型的片段:RoomFragment.java,fragment_room.xml和Roomviewmodel.java Fragment的视图绑定到xml,并且viewmodel在该xml中可用。

到目前为止一切顺利。

现在...我正在创建一个新的自定义视图对象:CustomView.kt ...并且我想在父视图(fragment_room.xml)中使用此自定义视图,并能够将CustomView中的按钮绑定到父视图模型中的方法

对于某些伪代码...(fragment_room.xml)

<ParentView>
    <data>
        <variable viewmodel>
    </data>

    <Button
        android:onClick:"@{viewmodel::onSomeButtonClick}"
        />

    <com.my.CustomView
        android:width
        android:height
        app:myCustomAction:@{viewmodel::onClickCustomButton}"
        />
</ParentView>

(当前已设置为字符串...但是更改它不会改变任何内容。)

<declare-styleable name="CustomView">
    <attr name="app:myCustomAction" format="string"/>
</declare-styleable>

错误 app:myCustomAction:@{viewmodel::onClickCustomButton}" 给我 Could not resolve viewmodel::onClickCustomButton as a listener.

有什么想法吗?还是有更好的方法...?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)