Shaiful
Shaiful

Reputation: 5673

Android - Same Id for multiple widget

I have multiple Activity. Some of the activity have same buttons such as "Continue" or "Cancel" etc. each of which have different actions. Now the question is, can I use same id for the button's in different activity? That is, Can I use "android:id="@+id="continue_button" for all the continue button's in different activity. Or should I use "continue_button_1" "continue_button_2" ...........

Upvotes: 9

Views: 5860

Answers (2)

ingsaurabh
ingsaurabh

Reputation: 15267

AFAIK you can use the same id in different activities because when you

setContentView(R.layout.splash);

and inflate layout then android itself searches for that particular id in that particular layout so no problem here.

Note: This doesn't means that you can put the same id for different element in same layout

Upvotes: 13

Sora
Sora

Reputation: 409

'Views may have an integer id associated with them. These ids are typically assigned in the layout XML files, and are used to find specific views within the view tree...View IDs need not be unique throughout the viewtree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching. ' (http://developer.android.com/reference/android/view/View.html)

Upvotes: 19

Related Questions