Vlad
Vlad

Reputation: 1797

Using same id for multiple buttons

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.

Upvotes: 6

Views: 8504

Answers (1)

Padma Kumar
Padma Kumar

Reputation: 20031

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.

Upvotes: 12

Related Questions