Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Phil White
PLUS
Phil White
Courses Plus Student 9,519 Points

Stuck on android improving our code challenge...

Let's continue to add color to MealActivity. In the onCreate() method, set the text color of foodLabel to Color.BLUE and then set the text color of drinkLabel to Color.GRAY.

And this is the code you start with

Phil White
Phil White
Courses Plus Student 9,519 Points
public class MealActivity extends Activity {

    public TextView foodLabel;
    public TextView drinkLabel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meal);

        foodLabel = (TextView) findViewById(R.id.foodTextView);
        drinkLabel = (TextView) findViewById(R.id.drinkTextView);
        RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
        mealLayout.setBackgroundColor(Color.GREEN);
    }
}

7 Answers

The GRAY needs to be capitalised.

foodLabel.setTextColor(Color.BLUE); drinkLabel.setTextColor(Color.Gray); That's what I put and it worked for me. I hope this helps.

This is what worked for me.

public class MealActivity extends Activity {

    public TextView foodLabel;
    public TextView drinkLabel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meal);

        foodLabel = (TextView) findViewById(R.id.foodTextView);
        foodLabel.setTextColor(Color.BLUE);


        drinkLabel = (TextView) findViewById(R.id.drinkTextView);
        drinkLabel.setTextColor(Color.GRAY);

        RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
        mealLayout.setBackgroundColor(Color.GREEN);
    }
}

What do you need, Juan?

Try something like, foodLabel.text.setTextColor(R.Color.BLUE);

Autocomplete will probably assist you too.

Steve.

Phil White
Phil White
Courses Plus Student 9,519 Points

Nope that didn't work, Thanks for trying to help tho

Second attempt ... foodLabel.setTextColor(Color.BLUE);

I'm opening Eclipse now and will see what I can figure out. What error are you getting?

Phil White
PLUS
Phil White
Courses Plus Student 9,519 Points

it just says "There is a compiler error. Please click on preview to view your syntax errors!"

and then in preview it says

./MealActivity.java:16: cannot find symbol symbol : variable Gray location: class Color drinkLabel.setTextColor(Color.Gray); ^ 1 error

Tom Spencer
Tom Spencer
7,713 Points

I was using = instead of a dot apparently it should have been a two coffee day today.

foodLabel = setTexColor(Color.BLUE); (SNAFU) Oddly enough when I put this foodLabel.setTextColor(Color.BLUE); all is good