Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the same id in different layout in Android?

I am new to Android development. Is it fine to use the same ID for images and TextViews in different Layout XML files?

When eclipse auto-list them for me, it lists all the layout variables from the project, so will it collide? Till now I have not noticed any problems using the same ID in different layouts, but I am concerned in long run.

like image 291
happyhardik Avatar asked Sep 08 '12 19:09

happyhardik


1 Answers

Short answer: Yes, you can.

Long answer: You can do this because whenever you use findViewById() to get a reference to a part of your layout, the method only looks for that view in the currently inflated layout. So even if you have another view with the same ID in another layout, Android will not look for it there.

like image 95
Raghav Sood Avatar answered Oct 11 '22 17:10

Raghav Sood