Created
April 5, 2015 14:40
-
-
Save eyeahs/87755c63ec89b8bb09ba to your computer and use it in GitHub Desktop.
Easy Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum EnumCode { | |
ABC(R.string.abc), | |
DEF(R.string.def), | |
GHI(R.string.ghi); | |
private final int stringResourceId; | |
public static EnumCode fromString(String name) { | |
for (EnumCode code : EnumCode.values()) { | |
if (code.name().equalsIgnoreCase(name)) { | |
return code; | |
} | |
} | |
return null; | |
} | |
EnumCode(int stringResourceId) { | |
this.stringResourceId = stringResourceId; | |
} | |
public boolean equalsName(String input) { | |
return name().equals(input); | |
} | |
public int getResourceId() { | |
return stringResourceId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment