How do I Load Your String Resources Programmatically from a Class file and not an Activity:
this is in my Strings.xml
<!-- FactBook Resource -->
<string-array name="facts">
<item>facts 1</item>
<item>facts 2</item>
...
</string-array>
Here my Class File
public class FactBook {
public String[] mFacts;
mFacts = getResources().getStringArray(R.array.facts);
public String getFact() {
String fact = "";
// Randomly select a fact
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(mFacts.length);
fact = mFacts[randomNumber];
return fact;
}
}
I get a erro. - Invalid Method declaration, return type required.
Load Your String Resources Pro-grammatically from a Class fileget callgetResources()you should need valid current componentContext. so useFactBookclass constructor for getting context during object creation and then access String array ascontext.getResources().getStringArray(R.array.facts)getResources()from outside. If you want then only using aContext.