0

If I have the exact same ImageView in two different activities, should each Image View have a unique ID in their respective XML files?

For example, I have a puzzle App. In activityOne, there are 4 ImageViews that show 4 blank animated boxes. When the user guesses the correct letter, the appropriate box is replaced with that letter. When they solve the puzzle, they are taken to PuzzleTwo in activityTwo. Let's say puzzleTwo is also 4 letters long. So I create 4 more ImageViews for this new puzzle. Should these ImageViews have IDs that are different from the previous puzzle? Thank you.

Mark F
  • 1,523
  • 3
  • 23
  • 41

1 Answers1

0

No it is not necessary to provide unique IDs across all XML files but it is better to do that for example when you use include.You can add your XML name as prefix to get unique IDs.

Docs say:

An ID need not be unique throughout the entire tree, but it should be unique within the part of the tree you are searching (which may often be the entire tree, so it's best to be completely unique when possible).

More details.

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167