Android - same id for multiple widget

I have several Activity. Some actions have the same buttons as Continue or Cancel, etc., each with different actions. Now the question is, can I use the same identifier for the button in different actions? That is, can I use "android:id="@+id="continue_button" for all continue buttons in different actions. Or should I use "continue_button_1" "continue_button_2" ...........

+8
android android-activity android-widget
source share
2 answers

'Views may have an integer identifier associated with them. These identifiers are usually assigned in XML layout files and are used to search for specific representations in the representation tree ... Viewing identifiers does not have to be unique in the entire viewing area, but it is good practice to make sure that they are at least unique within a part of the tree which you are looking for. '(http://developer.android.com/reference/android/view/View.html)

+18
source share

AFAIK, you can use the same identifier in different actions, because when you

 setContentView(R.layout.splash); 

and inflate the layout, then Android itself is looking for this particular identifier in this particular layout, so there is no problem.

Note. This does not mean that you can put the same identifier for another element in the same layout.

+13
source share

All Articles