开发者

Is android:id specific to xml file or the whole project?

开发者 https://www.devze.com 2023-01-04 20:58 出处:网络
Is the android:i开发者_如何学运维d=\"@+id/somevalue\" specific to the xml file in which it is defined, or the whole android project?

Is the android:i开发者_如何学运维d="@+id/somevalue" specific to the xml file in which it is defined, or the whole android project?

If it is project-wide, it seems like I have a lot of id's to come up for text fields. For example I have to name my "title" field like "title1" and "title2" etc...


They are unique on the whole project but can be used on different contexts. The reason is fairly simple: there will be just one R.id.name_of_id variable, though, they cannot be reference from anywhere. I mean, if you have and ID called @+id/my_id which is on the my_layout.xml file, you cannot use it unless you are currently working with my_layout.xml implicitly or explicitly. Implicity by using findViewById after a setContentView(R.layout.my_layout.xml) call (from the activity), or explicity by using it from an object (for instance, when you 'inflate' a layout and assign it to a View object you can do object.findViewById()).

0

精彩评论

暂无评论...
验证码 换一张
取 消