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.
Update:
Currently Android studio support refactoring with "refactor in current file only" option.
Update:ViewBinding
You can get casting exception if you have nested layouts (include tag) with view id's that clashed with id's in his hierarchy.