开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜