简体   繁体   English

为什么我应该使用R.id,而不是它生成的代码?

[英]Why should I use the R.id, as opposed to the code it generates?

I mean, besides code cleanliness, is it a preference, or a taboo? 我的意思是,除了代码清洁度之外,这是首选还是禁忌? I'm just curious. 我只是好奇。

For instance: 例如:

public static final class layout {
public static final int main=0x7f030000;

why not use "0x7f030000" instead of "R.id.main"? 为什么不使用“ 0x7f030000”代替“ R.id.main”?

The IDs generated in R.id are not static. R.id中生成的ID 不是静态的。 Any additional IDs you add to any of your XML files may change previously generated values. 您添加到任何XML文件中的任何其他ID可能会更改以前生成的值。 Therefore you should always use R.id.your_id as those are static. 因此,您应该始终使用R.id.your_id,因为它们静态的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM