how does multiple component with same id work in android?

后端 未结 3 1015
再見小時候
再見小時候 2021-01-23 04:59

I have defined several layouts, where few id\'s are multiple defined. I am confused how does it work? why doesn\'t it give error just like we get in java code? and most importan

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 06:06

    Using same id for different components in different layouts will not cause any problem. But you cannot use same id for different components in same layout.. Each time a new view is created a unique integer id is assigned to it, which can be found in the R.java file.. But even if we use same id for two components, only one entry is made in to the R.java file. However, it won't cause an error and this works if both components are in different xml layouts. [http://developer.android.com/reference/android/view/View.html][1]

    please find the ID section in this page. sorry if this is not what you were looking for

提交回复
热议问题