如何修复 android 的数据绑定无法识别 xml 文件中包含的某些视图的问题?
我最近克隆了一个旧项目,令我惊讶的是 2 个片段存在数据绑定问题。
1. 正如您在图片中看到的:我已经声明了绑定变量(34),并相应地对其进行了初始化(46)。
运行,应用程序可以编译,但 IDE 似乎无法识别我的 XML 文件上的某些视图。
这是我到目前为止所尝试的
- 通过将其设置为 false 并重新启用它来禁用数据绑定。
- 更改 XML 文件的名称,以便在我的绑定变量上获得不同的数据类型。
- 更改 Kotlin 端视图的名称,最终发出错误信号,因为数据绑定在 XML 端找不到它。
- 在 StackOverflow 上寻求帮助。
I've recently cloned an old project and to my surprise 2 fragments had issues with data binding.
1.
As you can see on the picture: Ive declared the binding variable(34), and initialized it accordingly(46).
2.
As seen on this function, some views are not recognized and some are.
The code works, the app compiles, but the IDE doesn't seem to recognize some of the views on my XML file.
Here's what I have tried so far
- Disable data binding by setting it to false and Re-enabling it.
- Changing the name of the XML file in order to get a different DataType on my binding variable.
- Changing the name of the view on Kotlin side, which ended up signaling an error because then data binding couldn't find it on the XML side.
- Ask for help on StackOverflow. ????
PS: After doing the steps above I've Invalidated the cache and restarted the IDE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能(我的意见),第一次编译项目时,在 xml 文件中,您有一些具有另一个 id 的视图(recyclerCast、recyclerTrailer 和 recyclerReview 您用另一个名称调用了它们),而其他视图您没有重命名它们(textview6 )
事实上,dataBinding“看到”的只是textview6。
理论上,如果您执行“清理项目”并在“重建项目”之后,FragmentTvSeriesDetailsBinding 类应该识别您为视图指定的新名称
Probably (my opinion), the first time you compiled the project, inside the xml file you had some views that had another id (recyclerCast, recyclerTrailer and recyclerReview you had called them with another name) while other views you did not rename them (textview6 )
In fact, the dataBinding "sees" you only textview6.
In theory if you do a 'Clean Project' and after a 'Rebuild Project' the FragmentTvSeriesDetailsBinding class should recognize the new names you have given to the views