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

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Using String Resources

Sayed Hamza Ahmed
Sayed Hamza Ahmed
1,349 Points

String 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

CodeChallenge.java
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "";
loadPuppiesButton.setText("LOAD");
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name ="See More Puppies">morePuppies</string>

</resources>

1 Answer

Harry James
Harry James
14,780 Points

Hey 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
Sayed Hamza Ahmed
1,349 Points

Thanks a lot man :D it worked !

Harry James
Harry James
14,780 Points

Glad 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
Sayed Hamza Ahmed
1,349 Points

can u please help me in the second code challenge ?

Sayed Hamza Ahmed
Sayed Hamza Ahmed
1,349 Points

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 = int.getStringExtra(R.string.buttonLable1) ;
loadPuppiesButton.setText("LOAD");

i am not getting what to do

Harry James
Harry James
14,780 Points

Sure 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
Sayed Hamza Ahmed
1,349 Points

Thank you so very much again brother :)