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 trialMUZ140118 Cathrine Makuya
10,300 Pointsstage 2 challenge 2
Now switch back to CodeChallenge.java. Set the buttonLabel variable to the new String resource you just added using the getString(int id) method. Don't forget: the id parameter will begin with R.string.
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "";
loadPuppiesButton.setText("LOAD");
intent.putExtra(getString(R.string.morePuppies),buttonLabel);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="morePuppies">See More Puppies</string>
</resources>
4 Answers
Gloria Dwomoh
13,116 PointsThe question says "Set the buttonLabel variable to the new String resource you just added using the getString(int id) method. "
In other words...get the string resource and assign it to the buttonLabel using the getString method is given as a hint. You were very close but it wants something simpler. Something like this should work.
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = getString(R.string.morePuppies);
loadPuppiesButton.setText("LOAD");
William Juste
7,822 PointsCan someone please explain to me why the "S" in the (R.string.stringname); isn't capitalized? I thought all Object names needed to be capped. Just curious as this is the reason why I got this wrong.
dimas aaron
6,660 PointsHi William, maybe this: it is only an XML naming for reference, but Java use capital as required, a class.
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 Pointsintent.putExtra (this, getString(R.string.label), buttonLabel);
this could work... not sure on this one...
Getting heavier -> didn't start with Android Dev yet.
MUZ140118 Cathrine Makuya
10,300 Pointsthanks
shiva csk
646 Pointswhat is hard-coded string??
Gonzalo Nunez
Courses Plus Student 5,064 Pointshard-coded is when you put a specific value to the parameter. Ex = String name =( " Shiva"); ( This is hard-coded to your name).
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 Pointsthanks Gloria.l will do as you have said
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsYou are welcome. It will help you improve a lot.
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 PointsGloria l am sorry to bother you but l have tried my best on the third challenge but its not even working can you please help for the last time please
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 Pointshere is the challenge Finally, use the buttonLabel variable to set the text for loadPuppiesButton instead of the current hard-coded String.
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsThat's quite simple. All it wants you to do is use your buttonLabel variable instead of the hard-coded "LOAD" string. In this way
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 Pointsthanks Gloria ....l see where l go wrong ...l did not remove the " " thanks