Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJason Holt
10,041 PointsChange the background color conditionally
I am trying to understand how to complete the second extra credit challenge at the end of Learning the Language. I am very stuck.
The challenge:
Change the background color conditionally Add "if" statements to check the value of the answer in the onClick() method. You can compare >it to the values stored in the mAnswers array of the CrystalBall object using the String.equals() >method. For example, answer.equals(crystalBall.mItems[0]) checks whether the answer equals the first >item in the array or not. Change the background color for certain answers or certain types of >answers, like make it red for negative answers and green for positive answers.
Here is what I have tried so far:
in the MainActivity.java and in CrystalBall.java I have tried to setup an if statement like this:
if (answer.equals(mAnswers.mItems[0])); "mItems cannot be resolved or is not a field"
I don't know where my understanding has broken down but I am missing something.
1 Answer
Jared M
3,680 PointsI need to see the provided code also. Are mAnswers and mItems related (mAnswers.mItems[0] looks fishy)?
Jason Holt
10,041 PointsJason Holt
10,041 PointsCrystalBall.Java
and MainActivity.java
I am trying to get the OnClick listener to change the color of the background based on the answer that is displayed from the array in CrystalBall.java
I am just trying to understand what I don't understand, the missing piece or pieces to set this up according to the challenge. My above code does not contain any of the trial code right now.