0

@+id/in an XML layout creates a new ID and @id/ just references it. I noticed that it doesn't seem to make a difference if I use @+id/ for the same ID several times. So are there any downsides in just using @+id/ all the time, even if I'm just referencing an existing ID?

Florian Walther
  • 6,237
  • 5
  • 46
  • 104
  • *it doesn't seem to make a difference if I use @+id/ for the same ID several times* - it does if you use it more than once in the same layout tree – Tim Apr 25 '18 at 09:21
  • Can you provide some code samples and some more explanation please? Your question is much easier to answer that way.. – Niels Vanwingh Apr 25 '18 at 09:22
  • You can use `@id/` for referring to id that has already been created . Read https://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android. If not satisfied with answer provide MCVE. – ADM Apr 25 '18 at 09:31
  • @TimCastelijns Yea you are right. I was playing around with the merge tag and placeholders, and there I could use it without a compiler warning – Florian Walther Apr 25 '18 at 09:31

1 Answers1

2

This question provides a nice discussion on this matter. One of the comments by Levit mentions:

there is also no negative runtime effect (possibly an unmeasurably small increase in compile time though)

So as far as I know the process of adding IDs to the R file happens during compile time, and there is no performance hit during runtime.

Suleyman
  • 2,765
  • 2
  • 18
  • 31