Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" ...........

like image 484
Shaiful Avatar asked Feb 24 '11 04:02

Shaiful


2 Answers

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

like image 23
ingsaurabh Avatar answered Sep 29 '22 14:09

ingsaurabh


'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)

like image 191
Sora Avatar answered Sep 29 '22 16:09

Sora