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
Jeremy Settlemyer
4,149 PointsModifying the Strings.xml file challenge
In the challenge it had us a a String item named "morePuppies" to the strings.xml file. That part passed correctly.
My question is that in the second part it then has us change the
String buttonLabel = "";
to
String buttonLabel = getString(morePuppies);
and finally the third part for setting the button label
loadPuppiesButton.setText(buttonLabel);
Is there a way that we can access a value from the strings.xml file without having to decalre and initialize a variable as in step 2. So are we able to just modify the text of the button by doing
loadPuppiesButton.setText(R.string.morePuppies);
1 Answer
Logan R
22,989 PointsHaving your code as
loadPuppiesButton.setText(R.string.morePuppies);
should work. If it doesn't for some reason, just simply add
loadPuppiesButton.setText(R.string.morePuppies + "");
and it will for sure work.
You can also always just try it out yourself in Android Studios :)