In my Android mobile app project, I am using Android Studio as an IDE. I have multiple activities there. Multiple of activities have xml element with the same name ("myTextView"). These are absolutely different xml textViews located in different layouts for different not related to each other activities. The only common thing is these textViews have similar id = "myTextView".
I try to rename xml element in xml layout for one activity. Say, in activity_layout1.xml I would like to rename "myTextView" to "someonesTextView". Android Studio automatically makes it via refactoring.
However, during refactoring, it renames elements with the same id (myTextView) in all the other activities. Finally, I have "someonesTextView" in other activities though they are not related.
How can I avoid that?
2
Answers
In that case, you don’t have to refactor the id but instead edit it from the Split or Code view of your xml file. This is because when you refactor or modify the id from the Design View, it modifies all other TextViews having the same id.
This is from my own personal experience since I faced what you are facing…
You can set a scope for the Rename refactoring (
idea 2020.3
). For example, close all tabs and open onlyactivity_main.xml
andMainActivity.java
files. Then, select id in xml (Refactor -> Rename) and in the Rename popup dialog under "Scope" select "Open Files" in order to rename the id in those files only.