Get Drawable resource from inside DefaultHandler
I have the following code that works on my main Activity but I have an extended DefaultHandler class and want to be able to access some resources.
How do I get the followin开发者_如何学编程g to work?
Drawable newMarker = this.getResources().getDrawable(R.drawable.generic2r);
You could reference the activity context with MyActivity.this, to produce:
Drawable newMarker = MyActivity.this.getResources().getDrawable(R.drawable.generic2r);
As long as you make sure that you only need your Handler from this specific activity.
Pass the context as a parameter to Your handler.
create an object of context and assign the main activity context to this object in main activity with the static specifier and access that object wherever you want
精彩评论