Using the same identifier for multiple buttons

Ok, I will say this:

I have a table with two columns. The first colum has the names of the items, the 2nd contains the number of logos / indicators (ImageButtons). Multiple Elements May Have The Same Logo .

My question is: can I assign multiple ImageButtons to the same identifier? I tried using android:id="@+id/logo1" in the first and then "android: id=@id /logo1" in all of the following cases. However, this does not work. I can probably assign each button a different identifier, and then just assign them to the same view, but it would be much easier if I could just repeat the same ImageButton identifier for all similar logos / indicators.

+6
source share
1 answer

No, you cannot use the same identifiers in the same layout if the behavior is different.

Yes, you can use the same identifiers, but in different layouts. This may actually be good practice.

Android has a default id here, they declare in ids.xml and reuse it in different views.

+12
source

Source: https://habr.com/ru/post/911558/


All Articles