I don't know if what I'm trying to do makes sense at all or if I should be doing it differently..if not, just ignore my current attempt and let me know what I should do!

I'm creating an app that displays the timetable for my school in a ListView. I'm using a CustomAdapter to display the data like subject, room, teacher, etc. I want to set the background color of the listview item depending on the subject. I've defined my colors in the colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Mat">#F44336</color>
<color name="Eng">#E91E63</color>
<color name="Deu">#9C27B0</color>
<color name="Kun">#673AB7</color>
<color name="Mus">#3F51B6</color>
<color name="Spo">#2196F3</color>
<color name="foreignLanguage">#03A9F4</color>
<color name="Bio">#00BCD4</color>
<color name="Phy">#009688</color>
<color name="Che">#8BC34A</color>
<color name="Geo">#CDDC39</color>
<color name="Soz">#FFEB3B</color>
<color name="Psy">#FFC107</color>
<color name="Phi">#FF9800</color>
<color name="Inf">#FF5722</color>
<color name="Ges">#795548</color>
<color name="Ast">#4CAF50</color>
<color name="freePeriod">#607D8B</color>
<color name="defaultColor">#9E9E9E</color>
</resources>

And in my custom adapter I do the following:

RelativeLayout itemLayout = (RelativeLayout) customView.findViewById(R.id.itemLayout);
int color;
if (result.getSubject().equalsIgnoreCase("BSB") ||
result.getSubject().equalsIgnoreCase("DLI") ||
result.getSubject().equalsIgnoreCase("BSB")) {
color = R.color.defaultColor;
} else if (result.getSubject().equalsIgnoreCase("---") &&
result.getRoom().equalsIgnoreCase("---")) {
color = R.color.freePeriod;
} else {
color = R.color.(result.getSubject());
}
itemLayout.setBackgroundColor(ContextCompat.getColor(getContext(), color));


I'm assigning the default color to two elements and an extra color if there's a free period. My problem is in the else statement. 
result.getSubject() returns a String that matches one of the color resource names from the xml file. So I'm trying to dynamically set this resource color id but that's not working. 
Is there any way I can do this or do I need to loop through every different subject and manually assign the color for it? 

Thanks!