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

前端 未结 4 1243
醉话见心
醉话见心 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条回答
  •  無奈伤痛
    2020-12-07 20:23

    Not recommended, because if in future you will need to refactor the view id, Android studio will refactor it in all XML files and classes and you will get into trouble.

    But there are also some cases when you do need to use same id for example if you have some abstract and you reuse multiple layouts.

    In case you have multiple views with same id's in your project and you need to refactor, do it manually, don't use build in IDE function, change the id in the target view inside XML layout then fix the red error inside layout.

提交回复
热议问题