Search code examples
androideclipseandroid-custom-viewcustom-view

declare properties with same name but different types


I am trying to declare properties for to different classes some of the properties have the same name but different types on different classes. Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="net.firouz.mastergardner.IntEditView">
        <attr name="caption" format="string" />
        <attr name="min_val" format="integer" />
        <attr name="max_val" format="integer" />
    </declare-styleable>
    <declare-styleable name="net.firouz.mastergardner.FloatEditView">
        <attr name="min_val" format="float" />
        <attr name="max_val" format="float" />
    </declare-styleable>    
</resources>

but eclipse complains that the attributes max_val and min_val have already been defined. How can I fix this.

Thank you Sam


Solution

  • I found a better answer with the help of this posting. Apparently attributes can have multiple formats which makes the following code valid and can work for me.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <attr name="min_val" format="float|integer|reference" />
        <attr name="max_val" format="float|integer|reference" />
        <declare-styleable name="IntEditView">
            <attr name="Caption" format="string|reference" />
            <attr name="min_val" />
            <attr name="max_val" />
        </declare-styleable>
        <declare-styleable name="FloatEditView">
            <attr name="min_val" />
            <attr name="max_val" />
        </declare-styleable>    
    </resources>
    

    Thank you everyone