Using same id for multiple buttons

Tom picture Tom · Mar 24, 2012 · Viewed 7.9k times · Source

Well, I'll say it like this.

I have a table with 2 columns. The first colum has names of items, the 2nd colums contains x amount of logos/indicators (ImageButtons). Several items can have the same logo/indicators.

My question is can I assign several ImageButtons to the same id? I've tried with using android:id="@+id/logo1" on the first and then "android:id=@id/logo1" on all the following occurences. This does not seem to work however. I can probably assign each button a different id and then just assign those to the same View, but it would be so much easier if I could just repeat the same ImageButton id for all the similar logos/indicators.

Answer

Padma Kumar picture Padma Kumar · Mar 24, 2012

No, you can't use the same ids in same layout if there behavior is different.

Yes, you can use the same ids but in different layouts. In fact, it may be good practice to.

Android has some default id here they are declaring in ids.xml and reusing it in different views.