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 trialSayed Hamza Ahmed
1,349 PointsString resources can be used throughout an app. In this challenge we want to use a String resource to set the text of a
what am i Doing wrong ? please help
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "";
loadPuppiesButton.setText("LOAD");
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name ="See More Puppies">morePuppies</string>
</resources>
1 Answer
Harry James
14,780 PointsHey Sayed!
You were close with the first part of the challenge! You just need to swap around the key and the value the other way round, like this:
<string name="The name of the String">The value of the String</string>
I'll then leave the rest of the challenge to you. See if you can complete it! If you get stuck along the way, give me a shout and I'd be happy to help out :)
Sayed Hamza Ahmed
1,349 PointsSayed Hamza Ahmed
1,349 PointsThanks a lot man :D it worked !
Harry James
14,780 PointsHarry James
14,780 PointsGlad to hear you got it sorted :)
If my answer helped, be sure to mark it as the Best Answer - it credits me and also lets other users know that the post has been answered.
Sayed Hamza Ahmed
1,349 PointsSayed Hamza Ahmed
1,349 Pointscan u please help me in the second code challenge ?
Sayed Hamza Ahmed
1,349 PointsSayed Hamza Ahmed
1,349 PointsNow 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.
i am not getting what to do
Harry James
14,780 PointsHarry James
14,780 PointsSure thing Sayed!
You've used getStringExtra() here but this is only used for when we want to get a String that we passed in as an Extra in an Intent.
Instead, as our String is stored in the String resources file, we just want to use the getString() method, passing in the resource ID for the String we want to get.
Hopefully this should explain it for you but if you get stuck on the way, let me know and I'll help you out a bit more :)
Sayed Hamza Ahmed
1,349 PointsSayed Hamza Ahmed
1,349 PointsThank you so very much again brother :)