2

I declared an android custom view that has an enum in it

   <attr name="ff_type" format="enum">
            <enum name="small" value="1" />
            <enum name="big" value="32" />
            <enum name="medium" value="8288" />

        </attr>

how to allow in my xml of the custom view to do app:ff_type="small|medium" ?

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

2 Answers2

1

Use flag rather than enum:

<attr name="ff_type" format="flag">
    <flag name="small" value="1" />
    <flag name="big" value="32" />
    <flag name="medium" value="8288" />
</attr>

Inclusion of format="flag" is optional.

8288 is an odd choice, you're better sticking to powers of 2. As it stands 8288 = 32 * 259. Therefore you can't select medium without implying big.

<attr name="ff_type">
    <flag name="small" value="1" />
    <flag name="medium" value="2" />
    <flag name="big" value="4" />
</attr>

Then you can optionally add additional values as shortcuts:

<attr name="ff_type">
    <flag name="small" value="1" />
    <flag name="medium" value="2" />
    <flag name="big" value="4" />
    <flag name="smallerThanBig" value="3" />
</attr>

So here smallerThanBig is the same as small|medium (but you can use both).

weston
  • 54,145
  • 21
  • 145
  • 203
0

<flag/>can be multiple,like gravity="center | left"
but <enum/> must be single,like layout_height="wrap_content"

moonlus
  • 31
  • 4