Id clash for "crime_solved"

On page 199, we’re instructed to change the id of the ImageView to “crime_solved”.
However, this id is already in use for the checkbox in fragment_crime.xml.
(This was set up back in chapter 7 on page 140).

Did I miss the instruction to remove fragment_crime.xml?
Is this an oversight - and I should simply assign a unique id to this ImageView?


1 Like

I noticed that too and changed the ID of my ImageView to solvedImageView. I think it’s just an oversight.

Thanks for reporting this. I’ve added it to our list of things to check out for the next edition.

But how is it possible that everything still works ok?

I understand that findVieById is scoped to the View object upon which the method is invoked. But contains just one crime_solved integer, so how is it possible that that integer maps to two totally different resources?

Ahh, I get it now.

Regarding the reuse of the id crime_id in fragment_crime.xml and list_item_crime.xml, note that the Android documentation states that ids need not be unique across the entire application. In our case, the build process generates a single crime_id integer in But then the question is, doesn’t that id map to a single view widget? (It doesn’t.) And if so, how can it be mapping to two different widgets? This is because the existence of these ids in is separate from how they are used. Each parent View object maintains its own tree of widgets. When building this tree, it uses the id values in But these view trees are independent - hence, we can use the same id in separate XML views. Despite this, it is not recommended to do this.

1 Like