使用databinding在GridView中使用标签查找视图

发布于 2025-02-04 02:04:39 字数 543 浏览 4 评论 0原文

我正在尝试将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文