2013-02-25 182 views
0

ImageRenderer.java安卓:活動

public class ImageRenderer implements Renderer { 
... 

private Context mActivityContext; 
... 

public SandAniRenderer(final Context activityContext) { 
    // TODO Auto-generated constructor stub 
    mActivityContext = activityContext; 
    mField = new Field(mActivityContext); 
    ... 
} 

private boolean InitializeObject(int width, int height) 
{ 
    ... 
    Field.SetField(width, height, R.drawable.image); 
    ... 

    return true; 
} 

Field.java

public class Field extends xxx{ 

private final Context mActivityContext; 

public Field(Context activityContext) 
{ 
    mActivityContext = activityContext; 
} 

public boolean SetField(int width, int height, int fn) 
{ 
    ImageView mImage = (ImageView) ((Activity) mActivityContext).findViewById(fn); 
... 
} 

,但它不能正常工作以外如何設置圖像查看!

mImage包含空的圖片

我找不到如何圖像包含活動之外。

你可以幫我介紹如何在活動之外實現繪製ImageView嗎?

回答

0

假設mField是一個成員變量,

public class ImageRenderer implements Renderer { 
Field mField = null; 

使用在InitializeObject。您的Context爲空,因爲它在靜態調用時沒有設置。

private boolean InitializeObject(int width, int height) 
{ 
... 
mField.SetField(width, height, R.drawable.image); 
... 

return true; 
} 

設置完

mField = new Field(mActivityContext); 
0

試試這個(emptyimage是像我在我的繪製)

mImage.setImageResource(R.drawable.emptyimage);