How would I set up this enum to return the image I want?

Posted by Justen on Stack Overflow See other posts from Stack Overflow or by Justen
Published on 2011-02-25T23:22:13Z Indexed on 2011/02/25 23:24 UTC
Read the original article Hit count: 321

Filed under:
|
|
|

I'm trying to set up this enum so that it has the ability to return the correct image, though I'm struggling with a way to incorporate the context since it is in a separate class.

public enum CubeType
{
    GREEN { 
        public Drawable getImage()
        {
            return Context.getResources().getDrawable( R.drawable.cube_green );
        }
    };

    abstract public Drawable getImage();
}

The error I'm getting is:

Cannot make a static reference to the non-static method getResources() from the type Context

© Stack Overflow or respective owner

Related posts about java

Related posts about android