You will have to pass a context
object to it. Either this
if you have a reference to the class in an activty, or getApplicationContext()
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
RegularClass regularClass = new RegularClass(this);
}
}
Then you can use it in the constructor (or set it to an instance variable):
public class RegularClass(){
private Context context;
public RegularClass(Context current){
this.context = current;
}
public findResource(){
context.getResources().getXml(R.xml.samplexml);
}
}
Where the constructor accepts Context
as a parameter
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…