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

help please

need stepbystep help, please and thank you

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

</resources>

It would help a lot if you gave us a description of what you're trying to do.

1 Answer

Okay, I went back and re-took the challenge. Here's an explanation of each step:

  1. You need to create a new string in the strings.xml file named "morePuppies". In XML we store data by putting it between tags (<tag> data </tag>). In Android Dev, you'll store this in a <string> tag with an attribute of name like so:
<resources>
    <string name="morePuppies">more puppies</string>
</resources>
  1. We need to access this data in our Java code. We do this using the getString(int) method where int is the integer ID of the string data we want to use. We'll get that using R.string.stringName and we'll put it all together like so:
buttonText = getString(R.string.morePuppies);
  1. Finally, we set the text of the button using the Button method setText(String) where String is the text we want to see in the button.
button.setText(buttonText);