开发者

Android - Same Id for multiple widget

开发者 https://www.devze.com 2023-02-12 21:26 出处:网络
I have multiple Act开发者_JAVA技巧ivity. 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

I have multiple Act开发者_JAVA技巧ivity. 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" ...........


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消