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 trial

Android

Changing the background color depending on weather (Build A Weather App)

I want to create an if else statement that will change the relative layout back ground color depending on what the icon for weather is. There is already a method to set each icon so at first i thought i could simply add mRelativeLayout.setBackGroundColor(Color.parseColor("Hex")); to each conditional that was there. I received a null pointer exception and my reference for the relative layout was incorrect. So i decided to make my own method for this and to have it all hooked up separately on the mainActivity. I'm sure how to do this and would appreciate any advice on how to set this up here is my code so far for the method. I have not run this and am not sure if it works or not.

<p> public RelativeLayout setBackGround() {

        if (mIcon.equals("clear-day")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#FFB300"));
        }
        else if (mIcon.equals("clear-night")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#121735"));
        }
        else if (mIcon.equals("rain")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#3C424C"));
        }
        else if (mIcon.equals("snow")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#EDEFF3"));
        }
        else if (mIcon.equals("sleet")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#B8B8B8"));
        }
        else if (mIcon.equals("fog")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#D3D2D3"));
        }
        else if (mIcon.equals("cloudy")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#C9CACA"));
        }
        else if (mIcon.equals("partly-cloudy-day")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#E8F3F7"));
        }
        else if (mIcon.equals("partly-cloudy-night")) {
            mRelativeLayout.setBackgroundColor(Color.parseColor("#7F706C"));
        }

        return
    } </p>