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 trialHolly Fox
2,808 PointsCan you move the facts to the String Resources?
My app was working until I tried to move all my facts to the Strings resources. I have tried to call the string ID's in my array but its not working. What am I doing wrong?
public String[] mFacts = {
Resources.getSystem().getString(R.string.fact1),
Resources.getSystem().getString(R.string.fact2),
Resources.getSystem().getString(R.string.fact3),
Resources.getSystem().getString(R.string.fact4),
Resources.getSystem().getString(R.string.fact5),
Resources.getSystem().getString(R.string.fact6),
};
1 Answer
James Pamplona
10,015 PointsThey go into this in more detail in the Blog Reader project but in the meantime, here's the gist of it.
In 'strings.xml', put your facts inside the 'resources' tag like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="facts_array">
<item>fact2</item>
<item>fact3</item>
<item>fact4</item>
</string-array>
</resources>
Then in your activity, you can fill the facts array like so:
public String[] mFacts = getResources().getStringArray(R.array.facts_array);
Hope this helps
Robert Mooers
1,858 PointsRobert Mooers
1,858 PointsNeat. I was wondering how to manage the facts in a group like this. I seem to have gone the long way with mine.
I have:
calling them via:
I spent an exorbitant amount of time trying to figure out if I could grab the R.string.fact_* ID's dynamically, to no success.