I am trying to use getResources method in a non-activity class. How do I get the reference to the “resources” object so that I can access the xml file stored under resources folder?
Example:
XmlPullParser xpp = getResources().getXml(R.xml.samplexml);
You will have to pass a
contextobject to it. Eitherthisif you have a reference to the class in an activty, orgetApplicationContext()Then you can use it in the constructor (or set it to an instance variable):
Where the constructor accepts
Contextas a parameter