2012-02-29 68 views
0

由于某种原因,我在android中派生了一个类BitmapDrawable,但我想知道如何为我的类指定资源ID(我的意思是绘图文件夹中的图标)?设置资源绘制到BitmapDrawable

作为资源对象的超级构造函数(但我的类无权访问 getResources()),因此如何将Resource id设置为BitmapDrawable。

但我认为越来越getResources不会帮我BitmapDrawable 没有(RES资源,INT ID)构造

static class DownloadedDrawable extends BitmapDrawable { 
     private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference; 

     public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask) { 

      bitmapDownloaderTaskReference = 
       new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask); 
     } 

     public BitmapDownloaderTask getBitmapDownloaderTask() { 
      return bitmapDownloaderTaskReference.get(); 
     } 
    } 

回答

2

你可以从你的活动设置的图像时,创建你的位图。或者您可以使用

getContext().getResources() 

从一个类

+0

我的班级是不活动 – Hunt 2012-02-29 22:31:59

+0

内获得的资源在哪里会这样呢? this.getContext()。getRseources()可以工作,我认为。 – ChristopheCVB 2012-02-29 22:44:38

+0

我知道这将工作,但我的课是一个单独的,并与一个异步 – Hunt 2012-03-01 04:54:09