我正在尝试设置这个枚举,以便它能够返回正确的图像,尽管我正在努力寻找合并上下文的方法,因为它位于一个单独的类中。
public enum CubeType
{
GREEN {
public Drawable getImage()
{
return Context.getResources().getDrawable( R.drawable.cube_green );
}
};
abstract public Drawable getImage();
}
我收到的错误是:
Cannot make a static reference to the non-static method getResources() from the type Context
最佳答案
我猜你可以有一个上下文作为 getImage() 的参数:
...
GREEN {
public Drawable getImage(Context c)
{
return c.getResources().getDrawable( R.drawable.cube_green );
}
};
...
}
关于java - 我将如何设置这个枚举来返回我想要的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5123807/