Can I use the same id in different layout in Android?

前端 未结 4 1255
醉话见心
醉话见心 2020-12-07 19:37

I am new to Android development. Is it fine to use the same ID for images and TextViews in different Layout XML files?

When eclipse auto-li

4条回答
  •  旧时难觅i
    2020-12-07 20:10

    It is recommended that you use different ids for different layouts. On the long run, when you will have a lot of layouts and therefor a lot of ids it will get very complicated to differentiate them.

    I usually name my ids like this: layoutName_elementId.

    It works for me to easily find the id I'm looking for, especially when using autocomplete (I know on what layout I'm working, but I don't really know the id; in this case, with my naming strategy, I only type the layout name and it brings on all the ids of that layout).

    More information on layouts and ids can be found here.

    Happy coding,

提交回复
热议问题