Charles Munger
Charles Munger

Reputation: 1407

Set the custom attributes of a subclass of a View with custom attributes?

If I have the following setup:

public class ABCView extends View {
    //implementation here
}

With the following custom attributes:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name = "ABCView" >
       <attr name="foo" format="boolean"/>
    </declare-styleable>
</resources>

If I want to subclass this View with another one, but still be able to specify the values of custom attributes in XML, how can I do that?

public class DEFView extends ABCView {
    //implementation here
}

But when I attempt to use the child view in XML, I get an error - it doesn't recognize that the attribute applies, as it doesn't seem to know about the relationship between the java classes. How can I handle this?

Upvotes: 2

Views: 300

Answers (1)

Dheeraj Bhaskar
Dheeraj Bhaskar

Reputation: 19039

Since XML won't about java class hierarchy, you might want to specify the custom attributes explicitly for the sub-sub-classed view as well.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name = "DEFView" >
       <attr name="foo" format="boolean"/>
    </declare-styleable>
</resources>

Upvotes: 2

Related Questions