Android Chapter 9 Creating User Interfaces with Layout and Widgets mSolvedImageView.setVisibility(crime.isSolved() ? View.VISIBLE: View.GONE);


Someone please explain this line of code to me:

        mSolvedImageView.setVisibility(crime.isSolved() ? View.VISIBLE: View.GONE);

Just to be clear, I understand most of the code and the ternary operator. My true question is, how is it that the mSolvedImageView now appear on every OTHER row for the list items. Thank you.


In the CrimeLab class you filled in the crime collection with a for loop. Inside the for loop you assigned a false or true to the isSolved variable for every other crime. (Due to the modulo operator: i % 2 == 0)
This true of false value is now being used to assign the visibility of the mSolvedImageView :slight_smile:

I hope this answered your question. If not, then I must have misunderstood your question.


Thank you very much for shinning light on that dark patch in my memory. I completely forgot about that for loop.