Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 following to work?

Drawable newMarker = this.getResources().getDrawable(R.drawable.generic2r);
like image 236
Lee Armstrong Avatar asked Jul 19 '11 14:07

Lee Armstrong


2 Answers

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.

like image 98
Marmoy Avatar answered Oct 22 '22 23:10

Marmoy


Pass the context as a parameter to Your handler.

like image 29
kzotin Avatar answered Oct 23 '22 00:10

kzotin