gpt4 book ai didi

android - BR 文件的数据绑定(bind)问题

转载 作者:行者123 更新时间:2023-11-29 19:06:36 25 4
gpt4 key购买 nike

我正在使用 <include>在父布局中包含一些布局。

问题:我的一些 viewModel 字段是在 BR 文件中生成的,有些丢失了。问题是什么?

描述:

  • <include> 中包含的布局中使用了缺失的字段标签。

  • 生成的字段用于父布局。

例如:

在下面的代码中,BR.name 变量名称在 BR 文件中生成并在父布局中使用。

public void setName(String phoneNumber){
this.phoneNumber = phoneNumber;
notifyPropertyChanged(BR.phoneNumber);
}

在下面的代码中,子布局中使用的 BR 文件中缺少密码。

public void setPassword(String password){
this.password = password;
notifyPropertyChanged(BR.password);
}

关于为什么会发生这种情况的任何帮助?

到目前为止我尝试了什么?

我重新启动了 android studio 并使其缓存无效,但仍然面临问题。

最佳答案

欢呼!我找到了解决方案 here在谷歌的官方网站。

“Bindable 注释在编译期间在 BR 类文件中生成一个条目。”

所以我只需要在 getter 上添加 @Bindable 注释。

关于android - BR 文件的数据绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46978725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com