I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.
Let's say I have 2 layouts, one named first_layout.xml
and second named second_layout.xml
. In each of these layouts, there is a view with id username_input
. This id is used in different activity classes to access target view, be it ButterKnife
binding, Kotlin Android Extensions
, or even findViewById
.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename
. What happens? Android Studio simply replaces id username_input
in the whole project, messing other layouts that had view the same id. Most people don't use a unique id for each and every view in the project since it's not mandatory, but I do because I do lots of refactoring, and many times I lost hours because of this non-contextual replacement in the project.
What are my options in this case? Is there a way to make Android Studio do the contextual replacement in such a situation, or should I keep making unique ids in my project?