[英]Can I use a colon in the id attribute in android?
I need help with something. 我需要一些帮助。 I found a code sample that does not fully understand.
我发现一个代码样本不能完全理解。 Can I use a colon in the id attribute?
我可以在id属性中使用冒号吗?
<TextView
android:id="@+id/Customer:Name" />
Thanks in advance. 提前致谢。
This is not very well documented on the official site, but there are certain types of punctuation that are allowed as part of the ID in a layout XML file, including semi-colons and periods. 官方网站上对此的记录不是很好,但是在布局XML文件中,某些类型的标点允许作为ID的一部分,包括分号和句点。 However, when you actually reference these ids in Java code, they are converted to underscores.
但是,当您实际在Java代码中引用这些ID时,它们会转换为下划线。 Thus something like this:
因此是这样的:
<TextView
android:id="@+id/customer.name"/>
Is referenced in java code like this: 在Java代码中引用如下:
getView().findViewById(R.id.customer_name);
It's legal (not an error) to do so, but it isn't a good practice, because it makes searching for the ID more difficult. 这样做是合法的(不是错误),但这不是一个好习惯,因为这会使搜索ID更加困难。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.