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

stage 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.

CodeChallenge.java
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "";
loadPuppiesButton.setText("LOAD");
intent.putExtra(getString(R.string.morePuppies),buttonLabel);
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

     <string name="morePuppies">See More Puppies</string>
</resources>

4 Answers

The 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");

thanks Gloria.l will do as you have said

You are welcome. It will help you improve a lot.

Gloria 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

here is the challenge Finally, use the buttonLabel variable to set the text for loadPuppiesButton instead of the current hard-coded String.

That's quite simple. All it wants you to do is use your buttonLabel variable instead of the hard-coded "LOAD" string. In this way

Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = getString(R.string.morePuppies);
loadPuppiesButton.setText(buttonLabel);

thanks Gloria ....l see where l go wrong ...l did not remove the " " thanks

William Juste
William Juste
7,822 Points

Can 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
dimas aaron
6,660 Points

Hi William, maybe this: it is only an XML naming for reference, but Java use capital as required, a class.

intent.putExtra (this, getString(R.string.label), buttonLabel);

this could work... not sure on this one...

Getting heavier -> didn't start with Android Dev yet.

thanks

what is hard-coded string??

hard-coded is when you put a specific value to the parameter. Ex = String name =( " Shiva"); ( This is hard-coded to your name).