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 :(得分: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);
答案 1 :(得分:0)
试试这个(空图像是我画中的图像)
mImage.setImageResource(R.drawable.emptyimage);