Wednesday, March 27, 2013

[android-developers] Get 'flag' or 'enum' int values in

My problem is quite simple. I've got a custom view which uses flags, for example

<declare-styleable name="MyStyleable">
    <attr name="someFlag">
        <flag name="first" value="0x01" />
        <flag name="second" value="0x02" />
        <flag name="third" value="0x03" />
    </attr>
</declare-styleable>

When constructing the instance of my class, I can retrive the value passed in xml using :

TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.ClickableLabelledIcon);
int flags = attributes.getInt(R.styleable.MyStyleable_someFlag, 0);

But I don't know how to compare programmatically with the values defined in my attrs.xml.


I saw that the sdk re-defines constants in classes (for example SDK demos shows this for Typeface), but I think this can lead to errors when refactoring, etc ...
Why are these values not accessible, or why i'm missing to get them ?


I saw that these flags result in some fields being defined in R.id.
I tried Context.getResources.getInteger(R.id.first) for example but it fails throwing a ResourceNotFoundException.

--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment