2011-10-19 44 views
0

我一直在嘗試在非活動類中加載位圖,但到目前爲止我所做的一切都失敗了。我甚至試圖發送上下文作爲參考,但這也會導致錯誤。getResources在非活動類

我現在的情況是這樣的:

// Surface class 
public class GameScreen extends SurfaceView implements Callback { 
    TileSet ts; 

    public GameScreen(Context context, AttributeSet attr) { 
     // Here I send context as a reference 
     ts = new TileSet(context, R.drawable.tiles); 
    } 
} 


// This is the class I need to get resources 
public class TileSet { 
    public TileSet(Context context, int id) { 
     Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), id); 

    } 
} 

任何想法?

回答

1

您是否嘗試過在活動中獲取位圖,然後將其傳遞給GameScreen的構造函數?

+0

我想到了這一點,但我希望會有另一種更好的解決方案..好吧,我會嘗試一下,它可能會工作......謝謝 – Lucas

+0

這不是一個必須的不雅行事方式。此外,如果您認爲我的回答良好,請立即投票和/或接受。 –