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 trialJoseph Greene
Courses Plus Student 7,638 PointsTrouble with strings
I'm having problems with question 2:
In StringTest.java add a String variable named 'label' before the call to setText(). Use the getString(int id) method to set 'label' to the value you just added in strings.xml. The id will begin with 'R.string'.
I know how to declare a variable, but I can't figure out what else to do here.
2 Answers
David Kaneshiro Jr.
29,247 PointsThe challenge wants you to set a String variable called label
to the value stored in the saveLabel
string resource that you added to the strings.xml file. To do that you would add the following line of code above the saveButton.setText()
method call.
String label = getString(R.string.saveLabel);
In the line above the getString() function returns the value saved in the saveLabel
XML entry of the strings.xml file and sets its value to our newly declared label
variable. R.string.saveLabel
tells the getString()
function to look at a resource string file for the XML item named saveLabel
.
Joseph Greene
Courses Plus Student 7,638 PointsThank you David for the help. That was exactly the answer. I think I just needed to get away from the computer for a moment to clear my head.