Get Drawable Resource from Inside DefaultHandler

I have the following code that works in my main activity, but I have an extended DefaultHandler class and you want to have access to some resources.

How do I get the following to work?

Drawable newMarker = this.getResources().getDrawable(R.drawable.generic2r); 
+7
source share
3 answers

You can reference the activity context with MyActivity.this to create:

 Drawable newMarker = MyActivity.this.getResources().getDrawable(R.drawable.generic2r); 

For now, make sure that you only need your handler from this particular action.

+11
source

Pass the context as a parameter to your handler.

+2
source

create a context object and assign the main activity context for this object in the main action using a static qualifier and access this object where you want

0
source

All Articles