Accessing XML Enumeration Values โโfrom Code
I have declared a styleable attribute with enum values โโlike:
<declare-styleable name="TileLayout">
<attr name="rotation" format="integer">
<enum name="top" value="0"/>
<enum name="left" value="1"/>
<enum name="right" value="2"/>
<enum name="bottom" value="3"/>
</attr>
</declare-styleable>
Now I would like to refer to those contained in my code, preferably in an expression switch
.
I can't seem to find a way to do this other than just hard-coding the values โโI have in the enum into my code (defeating half of the purpose of the enum in the first place).
Does anyone know how to do this?
EDIT
In response to @CommonsWare, tried this:
resources.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="rotation_top">0</integer>
</resources>
attrs.xml:
<resources>
<declare-styleable name="TileLayout">
<attr name="rotation" format="integer">
<enum name="top" value="@integer/rotation_top"/>
<enum name="left" value="1"/>
<enum name="right" value="2"/>
<enum name="bottom" value="3"/>
</attr>
</declare-styleable>
</resources>
This resulted in what was top
no longer an accepted meaning for rotation
.
source to share
You can try defining the values โโas whole resources and referring to the resources elsewhere (yours attrs.xml
and Java).
However, the IIRC operator, operator is switch
not possible without hard-coding in Java, since the operator switch
requires constant values โโfor sentences case
.
source to share