使用databinding在GridView中使用标签查找视图
我正在尝试将FindViewByid的通常使用转换为数据指标。看来很简单,但复杂性是该视图位于gridlayout内部,并且内部的每个视图都被标记了,因此我可以找到它们。当前代码是:
val layout: GridLayout =
binding.quickCommandGridLayout
val view: CardView = layout.findViewWithTag(name.toString())
val tileLayout: CardView = view.findViewById(R.id.tileLayout)
因此,我使用name
获取正确的cardView
我正在寻找,然后能够访问此cardView 它的工作原理正常,但是几乎整个应用程序都使用数据指标,因此我希望在应用程序中的一致性将我的
findViewById
转换为数据宾语。
有什么想法吗? 谢谢
I am trying to convert the usual use of findViewById to a databinding. It seems pretty straight forward but the complexity is that the view is inside a GridLayout and each view inside has been tagged so I can find them. The current code is :
val layout: GridLayout =
binding.quickCommandGridLayout
val view: CardView = layout.findViewWithTag(name.toString())
val tileLayout: CardView = view.findViewById(R.id.tileLayout)
So I am using the name
to get the proper CardView
I am looking for and then be able to access the element inside this CardView
it's working fine the way it is but almost the entire app is using databinding so I would like consistency in the app transform my findViewById
to databinding instead.
Any idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论