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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Paul Yorde](https://uploads.teamtreehouse.com/production/profile-photos/115085/micro_Screen_Shot_2016-05-05_at_12.18.28_PM.jpg)
Paul Yorde
10,497 PointsID to get a RelativeLayout object just like we get a TextView and Button.
Building a simple android app > learning the language > extra credit
So, are these:
- answerLabel
- getAnswerButton
Objects or variables in the following:
final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
I have tried to make a RelativeLayout object like this:
getBackgroundColor = findViewById(R.id.bgColor);
However, I'm not sure what to set parameter type or the object type (if this even the way I should be making an object?
5 Answers
![Jason Wiram](https://uploads.teamtreehouse.com/production/profile-photos/87526/micro_Moody_profile_crop.jpeg)
Jason Wiram
42,762 PointsTo answer the first part of your question about the following code:
final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
answerLabel is a variable of object type TextView and getAnswerButton is a variable of object type Button
This may hint toward your solution. Assuming you did as the instructions say and added an ID to the RelativeLayout element in activity_main.xml (it appears you used 'bgcolor' as your ID, then your java code is close but missing components.
getBackgroundColor = findViewById(R.id.bgColor);
Your code has a variable name, but no object type. As with the original code creating TextView and Button objects, you need to create a RelativeLayout object. This would look as follows:
RelativeLayout getBackgroundColor = (RelativeLayout) findViewById(R.id.bgColor);
Also notice that because the findViewById returns an object of type ID, you need to cast it as a (RelativeLayout) type to store in your variable 'getBackgroundColor'.
You will now be able to use RelativeLayout methods on your variable like setBackgroundColor() from the instructions:
getBackgroundColor.setBackgroundColor(Color.GREEN);
You can add this to your onClick() method to make the color change when that event happens.
![Matheus G Oliveira](https://uploads.teamtreehouse.com/production/profile-photos/740772/micro_WP_001393.jpg)
Matheus G Oliveira
9,682 PointsHey Paul,
First of all, have you tried to define the getBackgroundColor as you did on the TextView and Button? The thing is, if Eclipse say so, remeber to cast items on the getBackgroundColor naming, so it can correct it.
But... As i see you want to change background color. For that i recommend going to your_activity.xml and adding these
android:background="@color/white"
for other colors check for hexadecimal ones
i hope it helps
![Paul Yorde](https://uploads.teamtreehouse.com/production/profile-photos/115085/micro_Screen_Shot_2016-05-05_at_12.18.28_PM.jpg)
Paul Yorde
10,497 PointsThanks Matheus!
![Paul Yorde](https://uploads.teamtreehouse.com/production/profile-photos/115085/micro_Screen_Shot_2016-05-05_at_12.18.28_PM.jpg)
Paul Yorde
10,497 PointsThanks so much Jason--just what I was looking for!
![Jason Wiram](https://uploads.teamtreehouse.com/production/profile-photos/87526/micro_Moody_profile_crop.jpeg)
Jason Wiram
42,762 PointsNo problem. Glad it helped.
![Jake Henningsgaard](https://secure.gravatar.com/avatar/db805cae454680d6a0fdd1a70a819041?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jake Henningsgaard
1,284 PointsI'm also trying to do the same thing, but I can't figure out how to construct the 'ID' in the 'activity_main.xml'. I don't quite understand why I need to create a 'RelativeLayout' object and set its color to 'GREEN' when I'm trying to change the background color of the 'button' object.
![Joshua Friedman](https://secure.gravatar.com/avatar/c3594f1d71d194c977130ec3ba119f63?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Joshua Friedman
537 PointsSame here. It it just a matter of typing the following:
<RelativeLayout
android:id="@+id/backgroundColor"
/RelativeLayout>
In the .xml file, then calling that function in the main activity file? I tried that, then tried to manage my imports and nothing happened. I looked in the graphical editor and also didn't find anything there,