java - Android布局资源ID别名
问题描述
我编写了一个应用程序,它使用两个不同的片段来呈现不同的视频源。我对两个片段都有一个单独的布局文件,并且它们在两个布局文件中具有非常相似的结构(唯一的区别是视频表面和一个按钮)我有相同的按钮、文本视图等......我测试了应用程序,似乎工作正常,但现在我注意到片段 UI 元素共享相同的 id.... 检查和其他工具没有警告或发出任何信号,但我想知道这是否是一个坏习惯。
解决方案
No problem. just be sure to inflate the right layout file in onCreateView method of the fragment so the fragment class just knows the view and the ids which are defined in the inflated layout file.
But it is a good practice not to use same ids for views cause there might cause IDE autocomplete confusions for you in the future but in general no it's ok.
推荐阅读
- c# - 如何检测结尾有空格的单词(Regex - C#)
- java - AWS 上 ELB 的网关超时
- flutter - Flutter 使用 flutter_localizations 和 intl 手动更改语言
- python - 如何将列从一个 csv 文件复制到另一个 csv 文件?
- python-3.x - 如何在 spyder 控制台中复制粘贴 CP 测试用例?
- bash - BASH - 如果在发送 curl post 请求时服务器返回意外结果,如何在继续执行之前强制休眠 300 秒
- java - 我该如何为这种情况编写存储库方法?
- python - 带有自动完成和彩色文本的 Django Shell
- flutter - 我的颤动路径不允许颤动命令
- node.js - 将 id 传递给 NodeJS 网络套接字